1

我正在尝试分多个阶段构建 docker 映像。我的应用在起床后立即退出

我的 Dockerfile:

################# Builder #####################
FROM python:3.6 AS dependencies
COPY ./requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip install --user -r requirements.txt

################# Release #####################
FROM python:3.6-alpine AS release

WORKDIR /src/
COPY . /src

COPY --from=dependencies /root/.local /root/.local/

COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
RUN mv /src/wait-for /bin/wait-for
RUN chmod +x /bin/wait-for

ENV PATH=/root/.local/bin:$PATH

ENTRYPOINT [ "/entrypoint.sh" ]

我的码头工人撰写:

version: '3.4'
services:
    django_app:
        build: ./app
        command: sh -c "wait-for db:5432 && python manage.py collectstatic --no-input && python manage.py runserver 0.0.0.0:8000"
        ports:
            - "8000:8000"
        env_file:
            - ./.env
        volumes:
            - ./app:/src/
        restart: on-failure
    db:
         image: postgres:9.6
         volumes:
              - postgres_data:/var/lib/postgresql/data/
         environment:
             - POSTGRES_USER=${POSTGRESQL_DB_USER}
             - POSTGRES_PASSWORD=${POSTGRESQL_DB_PASSWORD}
             - POSTGRES_DB=${POSTGRESQL_DB_NAME}
         ports:
           - 5432:5432
         restart: on-failure

入口点.sh

#! /bin/sh

cd /src/ || exit

# Run migrations
echo "RUNNING MIGRATIONS" && python manage.py migrate

# echo "COLLECT STATIC" && python manage.py collectstatic --noinput

exec "$@"

如果我使用单阶段构建的 django 图像,一切正常。无法理解这里的问题。

4

0 回答 0