Official docs - Django - superfluous commands? #76

Open
opened 2025-11-06 14:18:04 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @SwampFalc on GitHub (Feb 28, 2023).

Hello,

Being quite new to Docker, I would like to ask about something that appears to be superfluous to me in the official Django docs.

The last line of the Dockerfile is:
COPY . /code/

But in the docker-compose.yml file, we have this statement:

    volumes:
      - .:/code

Is the first part not superfluous if the second part exists? Does it not simply make the image larger, without serving a purpose since the content of the folder gets overwritten by the mount anyway?

Or am I missing something?

Originally created by @SwampFalc on GitHub (Feb 28, 2023). Hello, Being quite new to Docker, I would like to ask about something that appears to be superfluous to me in the official Django docs. The last line of the Dockerfile is: ```COPY . /code/``` But in the docker-compose.yml file, we have this statement: ``` volumes: - .:/code ``` Is the first part not superfluous if the second part exists? Does it not simply make the image larger, without serving a purpose since the content of the folder gets overwritten by the mount anyway? Or am I missing something?
Author
Owner

@aleon1220 commented on GitHub (Nov 9, 2023):

did you try to test it by removing the COPY instruction?

@aleon1220 commented on GitHub (Nov 9, 2023): did you try to test it by removing the `COPY` instruction?
Author
Owner

@weslord commented on GitHub (Dec 21, 2024):

They do similar things, but have different purposes.

The /code/ directory in the image does get overwritten by the bind mount when you run docker compose. But the example compose file is for local development only, not for production (command: python manage.py runserver 0.0.0.0:8000). The bind mount is so your Django development server can reload files when you change them.

The Dockerfile copies /code/ to the image so you can use this same image in other contexts, like CI or production.

@weslord commented on GitHub (Dec 21, 2024): They do similar things, but have different purposes. The `/code/` directory in the image does get overwritten by the bind mount when you run docker compose. But the example compose file is for local development only, not for production (`command: python manage.py runserver 0.0.0.0:8000`). The bind mount is so your Django development server can reload files when you change them. The Dockerfile copies `/code/` to the image so you can use this same image in other contexts, like CI or production.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/awesome-compose#76