I have a simple Dockerfile that is in a directory called /App when I build my docker container using a docker-compose yaml file the dockerfile copies files from one level up, outside the /App folder into the container. Here is my dockerfile
FROM python:3.8
ENV PYTHONUNBUFFERED 1
WORKDIR /code
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
and here is my docker-compose file
version: '3'
services:
dash:
build:
context: ./App
dockerfile: Dockerfile.dash
container_name: dash_dash
command: ls
volumes:
- .:/code
ports:
- "80:8080"
When I build and run the container the ls command shows that it copied the directory one level above the /App directory, such that the /App directory is included but is not the main directory.
CodePudding user response:
The volumes
section of your docker-compose.yml
is overriding the working directory:
volumes:
- .:/code
is copying the whole folder where the docker-compose.yml
is (so it is copying the /App
folder entirely). As a result, your files in your working directory (/code
) are overridden.
You should remove the volumes
section of your docker-compose.yml
. The ls
command will then show the contents of the App
directory, copied by the COPY . .
section of your Dockerfile
.