Я хотел бы попробовать пример быстрого запуска на https://github.com/wrouesnel/postgres_exporter на хост-устройстве MacOS. В одном терминале я запускаю образ postgres
в интерактивном режиме в сети хоста:
> docker run --network=host -it --rm --env POSTGRES_PASSWORD=password postgres
Unable to find image 'postgres:latest' locally
latest: Pulling from library/postgres
8f91359f1fff: Pull complete
c6115f5efcde: Pull complete
28a9c19d8188: Pull complete
2da4beb7be31: Pull complete
fb9ca792da89: Pull complete
cedc20991511: Pull complete
b866c2f2559e: Pull complete
5d459cf6645c: Pull complete
cf66247ad881: Pull complete
35e29440d9da: Pull complete
362779251360: Pull complete
fb82d778d08d: Pull complete
b1f8d21ff25d: Pull complete
6d49eb0e8dd0: Pull complete
Digest: sha256:be456a40361cd836e0e1b35fc4d872e20e138f214c93138425169c4a2dfe1b0e
Status: Downloaded newer image for postgres:latest
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Etc/UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2019-10-03 19:06:10.222 UTC [42] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-10-03 19:06:10.235 UTC [43] LOG: database system was shut down at 2019-10-03 19:06:10 UTC
2019-10-03 19:06:10.239 UTC [42] LOG: database system is ready to accept connections
done
server started
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
waiting for server to shut down....2019-10-03 19:06:10.320 UTC [42] LOG: received fast shutdown request
2019-10-03 19:06:10.322 UTC [42] LOG: aborting any active transactions
2019-10-03 19:06:10.325 UTC [42] LOG: background worker "logical replication launcher" (PID 49) exited with exit code 1
2019-10-03 19:06:10.325 UTC [44] LOG: shutting down
2019-10-03 19:06:10.338 UTC [42] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2019-10-03 19:06:10.436 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2019-10-03 19:06:10.438 UTC [1] LOG: listening on IPv6 address "::", port 5432
2019-10-03 19:06:10.440 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-10-03 19:06:10.450 UTC [51] LOG: database system was shut down at 2019-10-03 19:06:10 UTC
2019-10-03 19:06:10.453 UTC [1] LOG: database system is ready to accept connections
, а в другом терминале запускаю postgres_exporter
и подключаю его к этой базе данных:
> docker run --net=host --env DATA_SOURCE_NAME="postgresql://postgres:password@localhost:5432/postgres?sslmode=disable" wrouesnel/postgres_exporter
Unable to find image 'wrouesnel/postgres_exporter:latest' locally
latest: Pulling from wrouesnel/postgres_exporter
0d6d2d2516f9: Pull complete
e9d7b571ef5e: Pull complete
Digest: sha256:aeea975f0efeacb49c170f0f7c4a4000d3f0099cc33437aedd3f276e628cde1c
Status: Downloaded newer image for wrouesnel/postgres_exporter:latest
time="2019-10-03T19:09:20Z" level=info msg="Established new database connection to \"localhost:5432\"." source="postgres_exporter.go:778"
time="2019-10-03T19:09:20Z" level=info msg="Semantic Version Changed on \"localhost:5432\": 0.0.0 -> 11.5.0" source="postgres_exporter.go:1238"
time="2019-10-03T19:09:20Z" level=info msg="Starting Server: :9187" source="postgres_exporter.go:1459"
Насколько я понимаю, я должен иметь возможность перейти к localhost:9187
в моем браузере и увидеть экспортированные метрики. Однако я получаю то, что в соединении отказывают:
> curl http://localhost:9187
curl: (7) Failed to connect to localhost port 9187: Connection refused
Я подозреваю, что это потому, что, как описано в https://docs.docker.com/network/host/,
Драйвер сетевого хостаработает только на хостах Linux и не поддерживается в Docker Desktop для Mac, Docker Desktop для Windows или Docker EE для Windows Server.
Является ли это причиной проблемы, и если да, то какЯ адаптирую этот пример быстрого запуска для работы с Docker Desktop для Mac?