Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving Docker build cache docs #20449

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Improving Docker build cache docs #20449

wants to merge 4 commits into from

Conversation

WillRy
Copy link

@WillRy WillRy commented Jul 21, 2024

Improving documentation, explaining that installing dependencies within the Dockerfile can be overwritten by volumes in development environments

Description

In this section we saw the importance of layer caching to deal with dependencies when packaging the application within the container, being an ideal scenario for production environments.

But remember, in development environments most of the time the application code is shared with the container through volumes, and the code is not copied into the image through Dockerfile

In these cases, it is not recommended run your package manager (NPM, Composer, Maven, Pip, etc.) inside the image, leave the installation to CMD or ENTRYPOINT. This is important so that the volume that we will normally share when developing does not overwrite the files installed by the package manager in the Dockerfile.

Some beginners, when looking at this documentation, will believe that they should always install dependencies within the Dockerfile, which is valid for production environments and several other scenarios, but in development, volumes can overwrite the installation of dependencies made within the Dockerfile

In the current doc, has this example:

FROM node
WORKDIR /app
COPY . .          # Copy over all files in the current directory
RUN npm install   # Install dependencies
RUN npm build     # Run build

However, if the user creates a volume sharing the code within the /app directory, node_modules will be overwritten by the volume and will lose its dependencies.

I believe it is worth inserting a new section in the documentation, alerting to this difference between the treatment of dependencies in development and production when there is the presence of volumes

Currently, there are other good suggestions regarding the same problem, such as:

20450 is the link to the similar issue.

Improving documentation, explaining that installing dependencies within the Dockerfile can be overwritten by volumes in development environments
@WillRy WillRy requested review from crazy-max and dvdksn as code owners July 21, 2024 16:20
@github-actions github-actions bot added the area/build Relates to Dockerfiles or docker build command label Jul 21, 2024
Copy link

netlify bot commented Jul 21, 2024

Deploy Preview for docsdocker ready!

Name Link
🔨 Latest commit 52e3a1a
🔍 Latest deploy log https://app.netlify.com/sites/docsdocker/deploys/673fbe9b56018e000866712a
😎 Deploy Preview https://deploy-preview-20449--docsdocker.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Luan1Schons added a commit to Luan1Schons/docs that referenced this pull request Jul 21, 2024
As per the following PR "docker#20449" explaining that installing dependencies within the Dockerfile can be rolled back across volumes in development environments, it is interesting that you are also warned about dependency managers.
@Luan1Schons
Copy link

Your suggestion is very useful and in agreement I also opened another pull request with the same suggestions and another point about volumes, I believe we can make the documentation more accessible about both scenarios.

PR#20450

Links with document references
@thompson-shaun
Copy link
Contributor

/cc @dvdksn

Copy link
Contributor

@dvdksn dvdksn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right section for this type of content.

I also think that you're better off splitting the Dockerfile into two stages instead: one stage for building the runtime image, and another stage for the dev environment.

I think that the compose section would be a more natural place for this information. @aevesdocker is there an existing page where this could fit?

@docker-robot
Copy link

docker-robot bot commented Nov 7, 2024

Thanks for the pull request. We'd like to make our product docs better, but haven’t been able to review all the suggestions.
As our docs have also diverged, we do not have the bandwidth to review and rebase old pull requests.

If the updates are still relevant, review our contribution guidelines and rebase your pull request against the latest version of the docs, then mark it as fresh with a /remove-lifecycle stale comment.
If not, this pull request will be closed in 30 days. This helps our maintainers focus on the active pull requests.

Prevent pull requests from auto-closing with a /lifecycle frozen comment.

/lifecycle stale

@WillRy
Copy link
Author

WillRy commented Nov 21, 2024

/lifecycle frozen

@github-actions github-actions bot added the area/get-started Relates to get started and onboarding docs label Nov 21, 2024
@WillRy
Copy link
Author

WillRy commented Nov 21, 2024

/remove-lifecycle stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build Relates to Dockerfiles or docker build command area/get-started Relates to get started and onboarding docs lifecycle/frozen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants