我在MacOS上运行Postgres应用程序,默认端口为5432:
我针对以下docker-compose up
运行了docker-compose.yml
:
version: "3.3"
services:
postgresql:
image: postgres:10.3-alpine
ports:
- "5432:5432"
environment:
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=admin
redis:
image: redis:4.0.9-alpine
ports:
- "6379:6379"
据我所知https://docs.docker.com/compose/compose-file/#ports,这会将主机上的端口5432映射到运行postgresql
服务的容器上的端口5432。
由于端口已经在使用,我运行docker-compose up
时会出现错误。但命令正常运行:
Kurts-MacBook-Pro-2:lucy-web kurtpeek$ docker-compose up
Creating network "lucy-web_default" with the default driver
Pulling postgresql (postgres:10.3-alpine)...
10.3-alpine: Pulling from library/postgres
ff3a5c916c92: Pull complete
a503b44e1ce0: Pull complete
211706713093: Pull complete
ea28caf317dd: Pull complete
a9b37749335b: Pull complete
f7e94ebc5400: Pull complete
77dd3a51253d: Pull complete
633a37734b12: Pull complete
872e6b940bbb: Pull complete
Digest: sha256:904fdb16d13c78577c26710b31c46a9e5c66db54099bc46a64e7ecf1d9346a63
Status: Downloaded newer image for postgres:10.3-alpine
Pulling redis (redis:4.0.9-alpine)...
4.0.9-alpine: Pulling from library/redis
ff3a5c916c92: Already exists
aae70a2e6027: Pull complete
87c655da471c: Pull complete
7f8fb829cc48: Pull complete
c72e0cff027d: Pull complete
276d6b52cd5b: Pull complete
Digest: sha256:8782054ba81c3b8b969dae4822263a97fc241a06f8f1fe1acacd7c077ec60831
Status: Downloaded newer image for redis:4.0.9-alpine
Creating lucy-web_redis_1 ... done
Creating lucy-web_postgresql_1 ... done
Attaching to lucy-web_redis_1, lucy-web_postgresql_1
redis_1 | 1:C 30 Apr 20:55:17.407 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 30 Apr 20:55:17.407 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 30 Apr 20:55:17.407 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 30 Apr 20:55:17.408 * Running mode=standalone, port=6379.
redis_1 | 1:M 30 Apr 20:55:17.408 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 30 Apr 20:55:17.408 # Server initialized
redis_1 | 1:M 30 Apr 20:55:17.408 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1 | 1:M 30 Apr 20:55:17.408 * Ready to accept connections
postgresql_1 | The files belonging to this database system will be owned by user "postgres".
postgresql_1 | This user must also own the server process.
postgresql_1 |
postgresql_1 | The database cluster will be initialized with locale "en_US.utf8".
postgresql_1 | The default database encoding has accordingly been set to "UTF8".
postgresql_1 | The default text search configuration will be set to "english".
postgresql_1 |
postgresql_1 | Data page checksums are disabled.
postgresql_1 |
postgresql_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgresql_1 | creating subdirectories ... ok
postgresql_1 | selecting default max_connections ... 100
postgresql_1 | selecting default shared_buffers ... 128MB
postgresql_1 | selecting dynamic shared memory implementation ... posix
postgresql_1 | creating configuration files ... ok
postgresql_1 | running bootstrap script ... ok
postgresql_1 | performing post-bootstrap initialization ... sh: locale: not found
postgresql_1 | 2018-04-30 20:55:17.689 UTC [29] WARNING: no usable system locales were found
postgresql_1 | ok
postgresql_1 | syncing data to disk ... ok
postgresql_1 |
postgresql_1 | Success. You can now start the database server using:
postgresql_1 |
postgresql_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
postgresql_1 |
postgresql_1 |
postgresql_1 | WARNING: enabling "trust" authentication for local connections
postgresql_1 | You can change this by editing pg_hba.conf or using the option -A, or
postgresql_1 | --auth-local and --auth-host, the next time you run initdb.
postgresql_1 | waiting for server to start....2018-04-30 20:55:18.156 UTC [34] LOG: listening on IPv4 address "127.0.0.1", port 5432
postgresql_1 | 2018-04-30 20:55:18.156 UTC [34] LOG: could not bind IPv6 address "::1": Address not available
postgresql_1 | 2018-04-30 20:55:18.156 UTC [34] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
postgresql_1 | 2018-04-30 20:55:18.159 UTC [34] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgresql_1 | 2018-04-30 20:55:18.171 UTC [35] LOG: database system was shut down at 2018-04-30 20:55:17 UTC
postgresql_1 | 2018-04-30 20:55:18.175 UTC [34] LOG: database system is ready to accept connections
postgresql_1 | done
postgresql_1 | server started
postgresql_1 | CREATE DATABASE
postgresql_1 |
postgresql_1 | CREATE ROLE
postgresql_1 |
postgresql_1 |
postgresql_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
postgresql_1 |
postgresql_1 | waiting for server to shut down....2018-04-30 20:55:18.538 UTC [34] LOG: received fast shutdown request
postgresql_1 | 2018-04-30 20:55:18.540 UTC [34] LOG: aborting any active transactions
postgresql_1 | 2018-04-30 20:55:18.541 UTC [34] LOG: worker process: logical replication launcher (PID 41) exited with exit code 1
postgresql_1 | 2018-04-30 20:55:18.541 UTC [36] LOG: shutting down
postgresql_1 | 2018-04-30 20:55:18.552 UTC [34] LOG: database system is shut down
postgresql_1 | done
postgresql_1 | server stopped
postgresql_1 |
postgresql_1 | PostgreSQL init process complete; ready for start up.
postgresql_1 |
postgresql_1 | 2018-04-30 20:55:18.643 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgresql_1 | 2018-04-30 20:55:18.643 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgresql_1 | 2018-04-30 20:55:18.646 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgresql_1 | 2018-04-30 20:55:18.656 UTC [47] LOG: database system was shut down at 2018-04-30 20:55:18 UTC
postgresql_1 | 2018-04-30 20:55:18.659 UTC [1] LOG: database system is ready to accept connections
为什么我没有收到错误?哪个数据库实际上应该在我本地计算机的端口5432上监听,Postgres应用程序是一个还是Docker容器中的一个?