X Tutup
The Wayback Machine - https://web.archive.org/web/20200917220541/https://github.com/nodejs/docker-node/issues/1293
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

Multiple apt-get install, purge commands #1293

Open
vinay-deshmukh opened this issue Jul 21, 2020 · 3 comments
Open

Multiple apt-get install, purge commands #1293

vinay-deshmukh opened this issue Jul 21, 2020 · 3 comments

Comments

@vinay-deshmukh
Copy link

@vinay-deshmukh vinay-deshmukh commented Jul 21, 2020

I was reading the Dockerfile for node:12-slim

And I have noticed that the apt-get install and apt-get purge commands are run twice.

For first installing node:

&& apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr xz-utils libatomic1 --no-install-recommends \

&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \

And then for installing yarn:

&& apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr --no-install-recommends \

&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \


Wouldn't it be efficient to run the purge commands after yarn has been installed?

This could be done by defining the YARN_VERSION environment variable before the first RUN command, and then using && to chain both the RUN commands together, where we install all needed packages before installing node, and then purge them after installing yarn.

@nschonni
Copy link
Member

@nschonni nschonni commented Jul 21, 2020

No, because leaving them in between the commands would leave the layers larger

@vinay-deshmukh
Copy link
Author

@vinay-deshmukh vinay-deshmukh commented Jul 21, 2020

No, because leaving them in between the commands would leave the layers larger

Wouldn't it be just one really long command, and hence it would be only 1 layer for the RUN command.

Let me show you a rough idea of what I mean:

Line 6 onwards:

ENV NODE_VERSION 12.18.2
ENV YARN_VERSION 1.22.4

RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
.
.
.
 && apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr xz-utils libatomic1 --no-install-recommends \
.
.
.

**(install node)**
&& find /usr/local -type f -executable -exec ldd '{}' ';' \
      | awk '/=>/ { print $(NF-1) }' \
      | sort -u \
      | xargs -r dpkg-query --search \
      | cut -d: -f1 \
      | sort -u \
      | xargs -r apt-mark manual \
**(test node)**
        && node --version \
        && npm --version
.
.
.

**(install yarn)**
&& find /usr/local -type f -executable -exec ldd '{}' ';' \
    | awk '/=>/ { print $(NF-1) }' \
    | sort -u \
    | xargs -r dpkg-query --search \
    | cut -d: -f1 \
    | sort -u \
    | xargs -r apt-mark manual \

**(test yarn)**
         && yarn --version

(finally purge all installed packages)
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false

The whole RUN command (which downloads packages, installs node, installs yarn, purges packages) should just create one single layer. There won't be any residual packages between the layers.

@nschonni
Copy link
Member

@nschonni nschonni commented Jul 21, 2020

I think they were split originally to allow updating Yarn without rebuilding the whole image, but since Yarn 1 is in maintenance mode, I don't think that matters much anymore. You could try PR'ing something to see if the other maintainers agree.
You probably need to update the *.template files and then run the update.sh script to regenerate them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.
X Tutup