I am playing with django project in docker and reality of the situation contradicts my limited understanding:
after I change file tests.py and run
docker exec {my_container} python manage.py test
it knows these local changes that I've made (for example I can write new test and it will run).
But I thought that docker containers are isolated and I need to recreate or at least copy updated file to one in order to update state of files.
I read docker exec doc but found no info about its ability to update files in container.
So, what do I need to know in order to understand what is happening?
content of Dockerfile:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD . /code/
RUN pip install -r requirements.txt
docker-compose.yml:
version: '3'
services:
ankete_db:
image: postgres
ports:
- "54320:5432"
container_name: ankete_db
ankete:
build: .
container_name: ankete
command: gunicorn -b 0.0.0.0:8000 ankete.wsgi
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- ankete_db
volumes in your docker-compose.yml does this. Once you remove volumes your changes shuldn't be reflected in a container.
The exec command does not update files between host and container. What is causing the files to be synced between container and host is the volume declared inside the compose file.
The volume declaration mounts the directory . onto /code inside the container, such that any changes done to any file inside the host current directory are reflected in the /code directory inside the container and vice versa.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With