vig*_*esh 3 docker docker-compose
我正在尝试了解 docker 示例应用程序“example-voting-app”。我正在尝试使用 docker-compose 构建应用程序。我对 docker compose 文件中的“command”键的行为和 Dockerfile 中的 CMD 指令感到困惑。该应用程序包含一项名为“投票”的服务。docker-compose.yml 文件中投票服务的配置为:
services: # we list all our application services under this 'services' section.
vote:
build: ./vote # specifies docker to build the
command: python app.py
volumes:
- ./vote:/app
ports:
- "5000:80"
networks:
- front-tier
- back-tier
Run Code Online (Sandbox Code Playgroud)
./vote 目录下提供的 Dockerfile 配置如下:
# Using official python runtime base image
FROM python:2.7-alpine
# Set the application directory
WORKDIR /app
# Install our requirements.txt
ADD requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
# Copy our code from the current folder to /app inside the container
ADD . /app
# Make port 80 available for links and/or publish
EXPOSE 80
# Define our command to be run when launching the container
CMD ["gunicorn", "app:app", "-b", "0.0.0.0:80", "--log-file", "-", "--access-logfile", "-", "--workers", "4", "--keep-alive", "0"]
Run Code Online (Sandbox Code Playgroud)
我的疑问是当我尝试使用 docker-compose up 构建应用程序时将执行哪个命令('python app.py' 或 'gunicorn app:app -b ...')
Docker Composecommand:或docker run图像名称后调用中的所有内容覆盖 Dockerfile CMD。
如果图像也有ENTRYPOINT,则您在此处提供的命令将作为参数传递给入口点,与 Dockerfile 相同CMD。
对于典型的 Compose 设置,您不需要指定command:. 在 Python/Flask 上下文中,它最有用的地方是,如果您还使用具有相同共享代码库的 Celery 之类的排队系统:您可以使用command:您构建的映像运行 Celery worker,而不是烧瓶应用。
| 归档时间: |
|
| 查看次数: |
558 次 |
| 最近记录: |