我正在尝试通过docker-compose运行应用程序。泊坞窗映像构建良好,它是在创建容器时发生问题/异常。我知道这肯定与涉及gunicorn的bash / sh命令有关。我只是不知道要解决我遇到的问题。
基本上,我运行以下命令:
docker-compose build
docker compose up
(是的,我知道您应该运行docker compose up -d,但是此方法通过控制台清楚地说明了我的问题)
我收到的特定错误消息是:
Creating network "flaskapi_default" with the default driver
Creating app ...
Creating app ... error
ERROR: for app Cannot start service api: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown
ERROR: for api Cannot start service api: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown
ERROR: Encountered errors while bringing up the project.
我尝试与docker-compose分别构建和运行dockerfile,但取得了不同程度的成功。这让我在ENTRYPOINT CMD问题中感到困惑。因此,我宁愿使用docker-compose。
Dockerfile:
FROM python:3.6-alpine3.7
RUN apk add --no-cache --update \
python3 python3-dev gcc \
gfortran musl-dev \
libffi-dev openssl-dev
RUN pip install --upgrade pip
ENV PYTHONUNBUFFERED 1
ENV APP /app
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir $APP
WORKDIR $APP
ADD requirements.txt .
RUN pip install -r requirements.txt
COPY . .
docker-compose文件:
version: "2"
services:
nginx:
image: nginx:latest
container_name: nginx
ports:
- "80:8000"
volumes:
- ./:/app
- ./config/nginx:/etc/nginx/conf.d
- ./config/nginx/ssl/certs:/etc/ssl/certs
- ./config/nginx/ssl/private:/etc/ssl/private
depends_on:
- api
api:
build: .
container_name: app
command: sh -c "gunicorn -w 1 -b 0.0.0.0:5000 manage:app"
expose:
- "5000"
我非常确定我的命令是正确的,它可以在我的开发环境(即MAC OS)中正常工作。在其他基于Linux的环境中会发生此问题。此特定摘录来自全新的ubuntu 18.04安装。
我已经尝试将/ bin / bash或/ bin / sh添加到docker-compose文件的bash或sh命令中,结果类似。我现在正在拔头发,很好,帮我obi-wan-kenobi。
使用/ bin / sh代替bash时的错误。这似乎更可能是答案,因为我能够确定某些Docker容器将不支持bash。
错误:
Creating network "flaskapi_default" with the default driver
Creating app ...
Creating app ... done
Creating nginx ...
Creating nginx ... done
Attaching to app, nginx
app | File "/bin/sh", line 1
app | SyntaxError: Non-UTF-8 code starting with '\xb1' in file /bin/sh on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
app exited with code 1
nginx_flask_api | 2019/09/06 19:25:33 [emerg] 1#1: host not found in upstream "api:5000" in /etc/nginx/conf.d/flask.conf:3
nginx_flask_api | nginx: [emerg] host not found in upstream "api:5000" in /etc/nginx/conf.d/flask.conf:3
nginx exited with code 1
仅需迭代,我就可以确定问题不在flask.conf中。
答案 0 :(得分:0)
所以我想出了解决方案。似乎ENTRPOINT和CMD不同。大惊喜。我只需要将/ bin / sh添加到docker-compose文件中,并从Dockerfile中删除对ENTRYPOINT的使用。
而且,很愚蠢的是,我没有附加使用ENTRYPOINT [“ python”]的原始错误的实例。删除该形式的dockerfile并将bin / sh添加到docker-compose文件似乎可以解决此问题。两个容器现在都在运行。