我正在使用以Python3.6为基础的docker镜像。突然之间,它开始崩溃(启动后立即退出)。所以我摔进了容器,发现
它崩溃是因为与容器化的postgres数据库的连接突然全部失败。
我设法得到的唯一错误输出是forward host lookup failed: Unknown host
,并不能告诉我太多信息。
entrypoint.sh:
echo "Waiting for postgres..."
while ! nc -z users-db 5432; do
sleep 0.1
done
echo "PostgreSQL started"
python manage.py run -h 0.0.0.0
错误输出:
Waiting for postgres...
users-db: forward host lookup failed: Unknown host
users-db: forward host lookup failed: Unknown host
users-db: forward host lookup failed: Unknown host
...
...
Dockerfile:
FROM python:3.6.9-slim
LABEL maintainer="abc"
RUN apt-get update && \
apt-get install -y netcat && \
apt-get clean
WORKDIR /usr/src/app
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
RUN chmod +x /usr/src/app/entrypoint.sh
COPY . /usr/src/app
CMD ["/usr/src/app/entrypoint.sh"]
让我吃惊的是,它到目前为止一直运行良好,并且没有我对数据库容器进行任何更改,连接就失败了。
我该怎么做才能解决此问题?如果您需要查看任何文件,请询问,我将在这里分享。
docker ps
:
72d344cc61bf tdd_nginx "nginx -g 'daemon of…" 25 minutes ago Restarting (1) 55 seconds ago tdd_nginx_1
8ee2f8082e69 tdd_client "npm start" 26 minutes ago Up 25 minutes 0.0.0.0:3007->3000/tcp tdd_client_1
1ccfc3ca5600 tdd_users-db "docker-entrypoint.s…" 26 minutes ago Up 26 minutes 0.0.0.0:5435->5432/tcp tdd_users-db_1
--> 62af29277b78 tdd_users "/bin/bash -s" 22 minutes ago Exited (130) 2 minutes ago # <-- keeps crashing
docker-compose文件:
version: '3.7'
services:
users:
build:
context: ./services/users
dockerfile: Dockerfile
volumes:
- './services/users:/usr/src/app'
ports:
- 5001:5000
environment:
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
- DATABASE_URL=postgres://postgres:postgres@users-db:5432/users_dev
- DATABASE_TEST_URL=postgres://postgres:postgres@users-db:5432/users_test
- SECRET_KEY=bart_simpson
depends_on:
- users-db
client:
build:
context: ./services/client
dockerfile: Dockerfile
volumes:
- './services/client:/usr/src/app'
- '/usr/src/app/node_modules'
ports:
- 3007:3000
environment:
- NODE_ENV=development
- REACT_APP_USERS_SERVICE_URL=${REACT_APP_USERS_SERVICE_URL}
depends_on:
- users
nginx:
build:
context: ./services/nginx
dockerfile: Dockerfile
restart: always
ports:
- 80:80
depends_on:
- users
- client
users-db:
build:
context: './services/users/project/db'
dockerfile: Dockerfile
ports:
- 5435:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
答案 0 :(得分:0)
问题是我安装了用于生成Web令牌的pyjwt库,并且在代码中使用了pyjwt.encode()
而不是jwt.encode()
。这对容器之间的连接功能产生了重大影响。还是不知道为什么。容器现在再次运行。如果有人投票结束这个话题,我会理解的,因为没人会猜到这个。