我是第一次接触docker,并试图创建一个简单的.NET应用程序,在docker容器中运行一些微服务.其中一个集装箱有一个Postgres数据库.
我的docker-compose.yml文件如下所示...
version: '3.4'
services:
catalogdb:
image: mongo
basketdb:
image: redis:alpine
discountdb:
image: postgres
portainer:
image: portainer/portainer-ce
catalog.api:
image: ${DOCKER_REGISTRY-}catalogapi
build:
context: .
dockerfile: Services/Catalog/Catalog.API/Dockerfile
basket.api:
image: ${DOCKER_REGISTRY-}basketapi
build:
context: .
dockerfile: Services/Basket/Basket.API/Dockerfile
discount.api:
image: ${DOCKER_REGISTRY-}discountapi
build:
context: .
dockerfile: Services/Discount/Discount.API/Dockerfile
volumes:
mongo_data:
portainer_data:
postgres_data:
我的docker-compose.override.yml文件如下所示...
version: '3.4'
services:
catalogdb:
container_name: catalogdb
restart: always
ports:
- "27018:27017"
volumes:
- mongo_data:/data/db
basketdb:
container_name: basketdb
restart: always
ports:
- "6379:6379"
discountdb:
container_name: discountdb
restart: always
ports:
- "5430:5432"
command: postgres
environment:
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=admin1234
- POSTGRES_DB=DiscountDb
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}" ]
interval: 10s
timeout: 5s
retries: 5
volumes:
- postgres_data:/var/lib/postgesql/data/
portainer:
container_name: portainer
restart: always
ports:
- "8080:8000"
- "9000:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
catalog.api:
container_name: catalog.api
environment:
- ASPNETCORE_ENVIRONMENT=Development
- "DatabaseSettings:ConnectionString=mongodb://catalogdb:27017"
depends_on:
- catalogdb
ports:
- "8000:80"
basket.api:
container_name: basket.api
environment:
- ASPNETCORE_ENVIRONMENT=Development
- "CacheSettings:ConnectionString=basketdb:6379"
depends_on:
- basketdb
ports:
- "8001:80"
discount.api:
container_name: discount.api
environment:
- ASPNETCORE_ENVIRONMENT=Development
- "DatabaseSettings:ConnectionString=Server=discountdb;Port=5430;Database=DiscountDb;User Id=admin;Password=admin1234;"
depends_on:
- discountdb
ports:
- "8002:80"
读了其他一些StackOverflow项目后,我的印象是,discount tdb部分的Health Check部分将确保Postgres连接保持打开,这样我的.Net服务就可以运行它的"种子"?
但当我奔跑的时候
docker-compose -f docker-compose.yml -f .\docker-compose.override.yml up -d
当我查看Portainer中的日志(log)时,我在折扣数据库的日志(log)中看到了以下内容...
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 dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: 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.
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2023-05-18 01:47:02.074 UTC [48] LOG: starting PostgreSQL 15.3 (Debian 15.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2023-05-18 01:47:02.076 UTC [48] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-05-18 01:47:02.083 UTC [51] LOG: database system was shut down at 2023-05-18 01:47:01 UTC
2023-05-18 01:47:02.090 UTC [48] LOG: database system is ready to accept connections
done
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
waiting for server to shut down....2023-05-18 01:47:02.289 UTC [48] LOG: received fast shutdown request
2023-05-18 01:47:02.291 UTC [48] LOG: aborting any active transactions
2023-05-18 01:47:02.293 UTC [48] LOG: background worker "logical replication launcher" (PID 54) exited with exit code 1
2023-05-18 01:47:02.293 UTC [49] LOG: shutting down
2023-05-18 01:47:02.295 UTC [49] LOG: checkpoint starting: shutdown immediate
2023-05-18 01:47:02.370 UTC [49] LOG: checkpoint complete: wrote 918 buffers (5.6%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.015 s, sync=0.054 s, total=0.077 s; sync files=250, longest=0.003 s, average=0.001 s; distance=4217 kB, estimate=4217 kB
2023-05-18 01:47:02.377 UTC [48] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2023-05-18 01:47:02.414 UTC [1] LOG: starting PostgreSQL 15.3 (Debian 15.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2023-05-18 01:47:02.414 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2023-05-18 01:47:02.414 UTC [1] LOG: listening on IPv6 address "::", port 5432
2023-05-18 01:47:02.418 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-05-18 01:47:02.424 UTC [64] LOG: database system was shut down at 2023-05-18 01:47:02 UTC
2023-05-18 01:47:02.429 UTC [1] LOG: database system is ready to accept connections
我错过了什么吗?我已经研究了其他需要安装或运行shell 命令的解决方案,但我在这里是个新手,不太熟悉如何做到这一点?