gpt4 book ai didi

node.js - 在docker中使用wait-for-it.sh时启动包不完整

转载 作者:行者123 更新时间:2023-12-02 19:47:52 24 4
gpt4 key购买 nike

我一直在尝试准备好容器化的node.js-postgres服务。
由于我的应用程序(节点)容器在postgres容器完全设置并准备好接收连接之前已经启动,因此我使用了wait-for-it.sh bash脚本。
我的应用程序的Dockerfile

FROM node:latest

WORKDIR /container

COPY wait-for-it.sh /usr/wait-for-it.sh
RUN chmod +x /usr/wait-for-it.sh

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 5800

CMD ["npm", "start"]
docker-compose.yml:
version: '3.7'
services:


postgres:
container_name: postgres
image: mdillon/postgis
environment:
POSTGRES_PASSWORD: rndpassword
POSTGRES_USER: postgres
POSTGRES_DB: geogis
PGDATA: /pgdata
volumes:
- ./pgdata:/var/lib/postgresql/data
ports:
- '5432:5432'

web:
container_name: app
restart: always
build: .
ports:
- '5800:5800'
depends_on:
- postgres
command: bash -c "/usr/wait-for-it.sh --timeout=0 postgres:5432"

撰写文件似乎要等待postgres容器被完全设置,但是我收到了“未完成启动”日志。该应用程序退出,我无法向该应用程序发送请求。
$ docker-compose up
Creating network "testsrv_default" with the default driver
Creating postgres ... done
Creating app ... done
Attaching to postgres, app
postgres | The files belonging to this database system will be owned by user "postgres".
postgres | This user must also own the server process.
postgres |
postgres | The database cluster will be initialized with locale "en_US.utf8".
postgres | The default database encoding has accordingly been set to "UTF8".
postgres | The default text search configuration will be set to "english".
postgres |
postgres | Data page checksums are disabled.
postgres |
postgres | fixing permissions on existing directory /pgdata ... ok
postgres | creating subdirectories ... ok
postgres | selecting default max_connections ... 100
postgres | selecting default shared_buffers ... 128MB
postgres | selecting dynamic shared memory implementation ... posix
postgres | creating configuration files ... ok
app | wait-for-it.sh: waiting 15 seconds for postgres:5432
postgres | running bootstrap script ... ok
postgres | performing post-bootstrap initialization ... ok
postgres | syncing data to disk ... ok
postgres |
postgres | Success. You can now start the database server using:
postgres |
postgres | pg_ctl -D /pgdata -l logfile start
postgres |
postgres |
postgres | WARNING: enabling "trust" authentication for local connections
postgres | You can change this by editing pg_hba.conf or using the option -A, or
postgres | --auth-local and --auth-host, the next time you run initdb.
postgres | waiting for server to start....2020-06-27 14:11:00.734 UTC [41] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2020-06-27 14:11:00.752 UTC [42] LOG: database system was shut down at 2020-06-27 14:10:59 UTC
postgres | 2020-06-27 14:11:00.758 UTC [41] LOG: database system is ready to accept connections
postgres | done
postgres | server started
postgres | CREATE DATABASE
postgres |
postgres |
postgres | /usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/postgis.sh
postgres | CREATE DATABASE
postgres | UPDATE 1
postgres | Loading PostGIS extensions into template_postgis
postgres | CREATE EXTENSION
postgres | CREATE EXTENSION
postgres | CREATE EXTENSION
postgres | CREATE EXTENSION
postgres | Loading PostGIS extensions into geogis
postgres | CREATE EXTENSION
postgres | CREATE EXTENSION
postgres | CREATE EXTENSION
postgres | CREATE EXTENSION
postgres |
postgres | waiting for server to shut down...2020-06-27 14:11:04.527 UTC [41] LOG: received fast shutdown request
postgres | .2020-06-27 14:11:04.535 UTC [41] LOG: aborting any active transactions
postgres | 2020-06-27 14:11:04.537 UTC [41] LOG: background worker "logical replication launcher" (PID 48) exited with exit code 1
postgres | 2020-06-27 14:11:04.548 UTC [43] LOG: shutting down
postgres | 2020-06-27 14:11:05.083 UTC [41] LOG: database system is shut down
postgres | done
postgres | server stopped
postgres |
postgres | PostgreSQL init process complete; ready for start up.
postgres |
postgres | 2020-06-27 14:11:05.139 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres | 2020-06-27 14:11:05.139 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres | 2020-06-27 14:11:05.144 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2020-06-27 14:11:05.158 UTC [87] LOG: database system was shut down at 2020-06-27 14:11:05 UTC
postgres | 2020-06-27 14:11:05.163 UTC [1] LOG: database system is ready to accept connections
postgres | 2020-06-27 14:11:05.727 UTC [94] LOG: incomplete startup packet
app | wait-for-it.sh: postgres:5432 is available after 7 seconds
postgres | 2020-06-27 14:11:06.125 UTC [95] LOG: incomplete startup packet
app | wait-for-it.sh: postgres:5432 is available after 0 seconds
app exited with code 0
postgres | 2020-06-27 14:11:06.643 UTC [96] LOG: incomplete startup packet
app | wait-for-it.sh: postgres:5432 is available after 0 seconds
app exited with code 0
postgres | 2020-06-27 14:11:07.358 UTC [97] LOG: incomplete startup packet
app | wait-for-it.sh: postgres:5432 is available after 0 seconds
app exited with code 0
postgres | 2020-06-27 14:11:08.485 UTC [98] LOG: incomplete startup packet
app exited with code 0
postgres | 2020-06-27 14:11:10.382 UTC [99] LOG: incomplete startup packet
app exited with code 0
postgres | 2020-06-27 14:11:13.895 UTC [100] LOG: incomplete startup packet
app exited with code 0

这种行为一直持续到我关闭容器为止。
我将不胜感激。

最佳答案

您应该通过命令行将npm start转换为wait_for_it.sh
您现在拥有的方式是,一旦wait-for-it.sh可以打开到postgres:5432的tcp连接并从而生成无害的“不完整的启动包”日志消息,则应用程序退出。
您想要的是让wait_for_it.sh在可以到达该端口时运行npm start
请在docker-compose.yml中尝试这样的操作:/usr/wait-for-it.sh --timeout=0 postgres:5432 -- npm start

关于node.js - 在docker中使用wait-for-it.sh时启动包不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62611376/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com