在 docker 的 pgadmin 中添加新的 postgres 服务器
Posted
技术标签:
【中文标题】在 docker 的 pgadmin 中添加新的 postgres 服务器【英文标题】:add new postgres server in pgadmin on docker 【发布时间】:2020-02-27 08:28:00 【问题描述】:我是 docker 和 postgres 的新手。我配置了 postgres 和 pgadmin4 服务容器,我想在 pgadmin 中创建一个新服务器。我通过检查指令获取postgres容器的IP为172.18.0.2
我的 postgres 检查结果如下:
[
"Id": "8a898f76c4ed5bc9e003c5d0be8ab67f7f7045fe1cc4c1cb82cc263136360c0a",
"Created": "2020-02-11T22:54:11.018152083Z",
"Path": "docker-entrypoint.sh",
"Args": [
"postgres"
],
"State":
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 4078,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-02-27T07:53:43.570077899Z",
"FinishedAt": "2020-02-27T07:35:12.205132013Z"
,
"Image": "sha256:b43856647ab572f271decd1f8de88b590e157bfd816599362fe162e8f37fb1ec",
"ResolvConfPath": "/var/lib/docker/containers/8a898f76c4ed5bc9e003c5d0be8ab67f7f7045fe1cc4c1cb82cc263136360c0a/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/8a898f76c4ed5bc9e003c5d0be8ab67f7f7045fe1cc4c1cb82cc263136360c0a/hostname",
"HostsPath": "/var/lib/docker/containers/8a898f76c4ed5bc9e003c5d0be8ab67f7f7045fe1cc4c1cb82cc263136360c0a/hosts",
"LogPath": "/var/lib/docker/containers/8a898f76c4ed5bc9e003c5d0be8ab67f7f7045fe1cc4c1cb82cc263136360c0a/8a898f76c4ed5bc9e003c5d0be8ab67f7f7045fe1cc4c1cb82cc263136360c0a-json.log",
"Name": "/google-ad-words-postgres",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig":
"Binds": [
"/host_mnt/c/wamp64/www/google-ad-words:/application:rw"
],
"ContainerIDFile": "",
"LogConfig":
"Type": "json-file",
"Config":
,
"NetworkMode": "google-ad-words_default",
"PortBindings":
"5432/tcp": [
"HostIp": "",
"HostPort": "8084"
]
,
"RestartPolicy":
"Name": "",
"MaximumRetryCount": 0
,
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
,
"GraphDriver":
"Data":
"LowerDir": "/var/lib/docker/overlay2/579907e185eaf689fe2fa0e75c7ccd207fd05f85154bda4887c836d60062c276-init/diff:/var/lib/docker/overlay2/0f235c1ebc1aad578ab2998c9727c8002c883e83f6076b325b69b16ed31f35eb/diff:/var/lib/docker/overlay2/3eab87840cf262453f6fa744c4ae61b77a26e75fcd48f4388f36120a70a680e7/diff:/var/lib/docker/overlay2/22e70ec746122772356fe213b9149f063c4eb97a5185c7dee8cb7c1ca1648086/diff:/var/lib/docker/overlay2/2fa1dbd50eba44c7e7c3c3c79c65467f0c754927750d691cd32253c048baf840/diff:/var/lib/docker/overlay2/5588b603da1c7139c0ff79edd158fa2579166156849c85457ce1ef9542d6be0f/diff:/var/lib/docker/overlay2/a3c4096b7b08d323bad09f959b23c7ed96764fc90569528ba0774b9ce63d0013/diff:/var/lib/docker/overlay2/800f19b5767d6598088c8ac4d64e6bab0421226665db0e505e3500563284d668/diff:/var/lib/docker/overlay2/67e3730eeaeac3411e5d54eb6cd34c6e5fa486138d0e0d9e1bf135336ef7ccc6/diff:/var/lib/docker/overlay2/0b092310839803394dd4a830ae2143930d47f8e86173cb46bd4a3e29f4ec87cb/diff",
"MergedDir": "/var/lib/docker/overlay2/579907e185eaf689fe2fa0e75c7ccd207fd05f85154bda4887c836d60062c276/merged",
"UpperDir": "/var/lib/docker/overlay2/579907e185eaf689fe2fa0e75c7ccd207fd05f85154bda4887c836d60062c276/diff",
"WorkDir": "/var/lib/docker/overlay2/579907e185eaf689fe2fa0e75c7ccd207fd05f85154bda4887c836d60062c276/work"
,
"Name": "overlay2"
,
"Mounts": [
"Type": "bind",
"Source": "/host_mnt/c/wamp64/www/google-ad-words",
"Destination": "/application",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
,
"Type": "volume",
"Name": "3b62664927156c94ba1f570c4082246755f1b66f6f4dd3ea6e00e7f84099bee9",
"Source": "/var/lib/docker/volumes/3b62664927156c94ba1f570c4082246755f1b66f6f4dd3ea6e00e7f84099bee9/_data",
"Destination": "/var/lib/postgresql/data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
],
"Config":
"Hostname": "8a898f76c4ed",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts":
"5432/tcp":
,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"POSTGRES_USER=root",
"POSTGRES_PASSWORD=toor",
"POSTGRES_DB=core-db",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=en_US.utf8",
"PG_MAJOR=11",
"PG_VERSION=11.1",
"PG_SHA256=90815e812874831e9a4bf6e1136bf73bc2c5a0464ef142e2dfea40cda206db08",
"PGDATA=/var/lib/postgresql/data"
],
"Cmd": [
"postgres"
],
"Image": "postgres:11.1-alpine",
"Volumes":
"/application": ,
"/var/lib/postgresql/data":
,
"WorkingDir": "/application",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels":
"com.docker.compose.config-hash": "b42b467fdb058676db6aac2de623ca4dc24d602d25bdbe5538f03270d1394dda",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "google-ad-words",
"com.docker.compose.project.config_files": "docker-compose.yml",
"com.docker.compose.project.working_dir": "C:\\wamp64\\www\\google-ad-words",
"com.docker.compose.service": "postgres",
"com.docker.compose.version": "1.25.4"
,
"NetworkSettings":
"Bridge": "",
"SandboxID": "b6e5d1edca6b3dd27ca26fa038747fb08926dec8b9a8594d1d6160998f1caaa0",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports":
"5432/tcp": [
"HostIp": "0.0.0.0",
"HostPort": "8084"
]
,
"SandboxKey": "/var/run/docker/netns/b6e5d1edca6b",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks":
"google-ad-words_default":
"IPAMConfig": null,
"Links": null,
"Aliases": [
"postgres",
"8a898f76c4ed"
],
"NetworkID": "340ce7b63f7790542cd04ec8ff7f55cd5847f38d113f6e444e369919e6fc44fb",
"EndpointID": "bc62ec297e23d83ae468fe76d2ca12647c594521f445d6d5a2fbed658481fa1a",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:02",
"DriverOpts": null
]
当我想从 pgadmin 添加服务器时,出现以下错误。 timeout expired error。 我该如何解决这个问题? 谢谢...
【问题讨论】:
你能提供docker-compose.yml
或者你是如何开始这一切的
@Jean-JacquesMOIROUX 这是我所有的 docker-compose.yml 内容:nkwall.ir/docker-compose.yml
【参考方案1】:
语法在环境中很奇怪。创建一个包含您的秘密的 .env 文件,然后从 docker-compose 加载它
.env
PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org
PGADMIN_DEFAULT_PASSWORD=admin
PGADMIN_PORT=5050
docker-compose.yml
version: "3.1"
services:
memcached:
image: memcached:alpine
container_name: google-ad-words-memcached
postgres:
image: postgres:11.1-alpine
container_name: google-ad-words-postgres
working_dir: /application
volumes:
- .:/application # prefer absolute path on host
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=toor
- POSTGRES_DB=core-db
ports:
- "8084:5432"
networks: # <-- Add this line
- postgres # <-- Add this line
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin_container
working_dir: /application
env_file: # <-- Add this line
- .env # <-- Add this line
volumes:
- pgadmin:/root/.pgadmin
environment:
# - PGADMIN_DEFAULT_EMAIL=$PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org # <-- Wrong this
# - PGADMIN_DEFAULT_PASSWORD=$PGADMIN_DEFAULT_PASSWORD:-admin # <-- Wrong this
- PGADMIN_DEFAULT_EMAIL=$PGADMIN_DEFAULT_EMAIL # <-- Right this
- PGADMIN_DEFAULT_PASSWORD=$PGADMIN_DEFAULT_PASSWORD # <-- Right this
ports:
# - "$PGADMIN_PORT:-5050:80" # <-- Wrong this
- "$PGADMIN_PORT:80" # <-- Right this
networks:
- postgres
restart: unless-stopped
webserver:
image: nginx:alpine
container_name: google-ad-words-webserver
working_dir: /application
volumes:
- .:/application # prefer absolute path on host
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf # prefer absolute path on host
ports:
- "8080:80"
php-fpm:
build: phpdocker/php-fpm
container_name: google-ad-words-php-fpm
working_dir: /application
volumes:
- .:/application # prefer absolute path on host
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini # prefer absolute path on host
networks:
postgres:
driver: bridge
volumes:
postgres:
#pgadmin: # <-- Not used, remove it
【讨论】:
我尝试了类似的方法,但使用./config.env
而不是.env
。我收到有关未设置变量的错误。 It turns out,一般来说env_file:
只设置runtime环境中的变量(在容器中),所以不能用于在yaml文件中填写$my_var
。 .env
是特殊的,在解析 yaml 文件之前被读取和设置。 (实际上它甚至根本不需要env_file:
条目)。这就是为什么它可以用来填充$my_var
以上是关于在 docker 的 pgadmin 中添加新的 postgres 服务器的主要内容,如果未能解决你的问题,请参考以下文章
docker postgres pgadmin 本地连接