当构建容器时,docker-compose
Dockerfile 没有错误,并且有效地复制了文件,但是在构建映像之后,docker-compose 使用command: ls -la /app
并且文件不存在。
设置如下:
docker-compose.yml
version: '3.8'
services:
web:
build:
context: .
dockerfile: Dockerfile
command: ls -la /app
volumes:
- ./ecommerce:/app
ports:
- "8000:8000"
depends_on:
- redis
- rabbitmq
environment:
- DEBUG=${DEBUG}
- DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}
- DJANGO_ALLOWED_HOSTS=${DJANGO_ALLOWED_HOSTS}
- DEVELOPMENT_MODE=${DEVELOPMENT_MODE}
- STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY}
- STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
- STRIPE_WEBHOOK_SECRET=${STRIPE_WEBHOOK_SECRET}
- REDIS_HOST=redis
- CELERY_BROKER_URL=amqp://guest:guest@rabbitmq:5672//
redis:
image: redis:alpine
rabbitmq:
image: rabbitmq:3-management
ports:
- "5672:5672"
- "15672:15672"
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
Dockerfile
# Use the official Python image from the Docker Hub
FROM python:3.9-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set the working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
libpango1.0-0 \
libcairo2 \
libgdk-pixbuf2.0-0 \
libffi-dev \
shared-mime-info \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt /app
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
# Copy the entrypoint script into the container
COPY ./entry/entrypoint.sh /app <--- this runs OK but it not listed in the container
RUN chmod +x /app/entrypoint.sh
# Copy the Django project code into the container
COPY ./ecommerce /app
# Collect static files
RUN python manage.py collectstatic --noinput