为了用一个docker-compose.yml文件为两个网站提供服务,正在尝试运行1个Nginx容器和2个uWSGI容器,但在构建之后,两个Python服务器最终都运行相同的命令,而不是在各自的Dockerfile中编写的命令。下面是一个解释。
目录结构如下:
.
├── app-aifriendly
│ ├── app.ini
│ ├── app.py
│ ├── Dockerfile
│ └── requirements.txt
├── app-bitcoin
│ ├── app.ini
│ ├── app.py
│ ├── Dockerfile
│ └── requirements-bitcoin.txt
├── app.conf
├── docker-compose.yml
└── Dockerfile-nginx
docker-compose.yml文件如下:
version: '2'
services:
flask2bitcoin:
image: webapp-flask
build:
context: ./app-bitcoin
dockerfile: Dockerfile
ports:
- "5001:5001"
volumes:
- "./app-bitcoin:/app-bitcoin"
environment:
- APP_NAME=flask2
flask:
image: webapp-flask
build:
context: ./app-aifriendly
dockerfile: Dockerfile
ports:
- "5000:5000"
volumes:
- "./app-aifriendly/:/app"
- "./app-aifriendly/uploads:/uploads"
environment:
- FLASK_DEBUG=1
- FLASK_ENV=development
- APP_NAME=flask
nginx:
image: webapp-nginx
build:
context: .
dockerfile: Dockerfile-nginx
ports:
- "80:80"
- "443:443"
volumes:
- "./app.conf:/etc/nginx/conf.d/app.conf"
depends_on:
- flask
volumes:
uploads:
并且";app aifriendly"s Dockerfile如下:
# We simply inherit the Python 3 image. This image does
# not particularly care what OS runs underneath
FROM python:3.6
# Set an environment variable with the directory
# where we'll be running the app
ENV APP /app
# Create the directory and instruct Docker to operate
# from there from now on
RUN mkdir $APP
WORKDIR $APP
# Expose the port uWSGI will listen on
EXPOSE 5000
# Copy the requirements file in order to install
# Python dependencies
COPY . .
# Install Python dependencies
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt
# Finally, we run uWSGI with the ini file we
# created earlier
CMD [ "uwsgi", "--ini", "app.ini" ]
而";应用比特币";s Dockerfile如下:
# We simply inherit the Python 3 image. This image does
# not particularly care what OS runs underneath
FROM python:3.6
# Set an environment variable with the directory
# where we'll be running the app
ENV APP2 /app-bitcoin
# Create the directory and instruct Docker to operate
# from there from now on
RUN mkdir $APP2
WORKDIR $APP2
# Expose the port uWSGI will listen on
EXPOSE 5001
# Copy the requirements file in order to install
# Python dependencies
COPY . .
# Install Python dependencies
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements-bitcoin.txt
# Finally, we run uWSGI with the ini file we
# created earlier
#CMD [ "uwsgi", "--ini", "app.ini" ]
CMD ["python3", "void.py"]
在一天结束时,运行
docker-compose up -d
然后是
docker-compose ps
产生
aifriendly_flask2bitcoin_1 uwsgi --ini app.ini Up 0.0.0.0:5000, 0.0.0.0:5001->5001/tcp
aifriendly_flask_1 uwsgi --ini app.ini Up 0.0.0.0:5000->5000/tcp
aifriendly_nginx_1 /docker-entrypoint.sh ngin Up 0.0.0.0:443->443/tcp,
... 0.0.0.0:80->80/tcp
但根据";应用比特币";s Dockerfile称为";flask2bitcoin_ 1";应该运行
python void.py
---------------进一步信息------------------
运行
docker exec -it 'container name' /bin/sh
表明";app aifriendly"s的根包含一个名为"的目录;app";,而";应用比特币";s的根包含一个名为"的目录;应用比特币";(预期(和";应用程序";(出乎意料(。特别地,两个壳都在";应用程序";目录,这让我相信orcestator配置不正确。
感谢您抽出时间!
它们看起来不一样,如果是,你确定你指定了不同的Dockerfiles吗?