【发布时间】:2020-05-14 18:08:28
【问题描述】:
我正在尝试了解 docker 示例应用程序“example-voting-app”。我正在尝试使用 docker-compose 构建应用程序。我对 docker compose 文件中的“命令”键的行为和 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
./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"]
我的疑问是,当我尝试使用 docker-compose up 构建应用程序时,将执行哪个命令('python app.py' 或 'gunicorn app:app -b ...')
【问题讨论】:
标签: docker docker-compose