docker: recomendations on docker image format and layers
I am trying to structure my docker image so it is small but I am not sure if this is a good pattern for keeping each layer small. Open for any recomendations?
The main points I am curious about are relating to the "update" and "rm" with each layer. Should i be doing it this way or is there a better method.
# our base image
FROM ubuntu
ENV DEBIAN_FRONTEND "noninteractive apt-get autoremove"
RUN apt-get update && apt-get install -y locales
&& locale-gen en_AU.UTF-8
&& dpkg-reconfigure locales
&& rm -rf /var/lib/apt/lists/*
ENV LANG en_AU.UTF-8
ENV LANGUAGE en_AU.UTF-8
ENV LC_ALL en_AU.UTF-8
ENV LC_CTYPE=en_AU.UTF-8
ENV TZ="Australia/Adelaide"
# networking and routing tools
RUN apt-get update && apt install -y
net-tools telnet dnsutils inetutils-traceroute
curl jq
postgresql redis-tools mongodb-clients
&& rm -rf /var/lib/apt/lists/*
# node libs for test scripts
RUN apt-get update && apt-get install -y
nodejs
npm
&& rm -rf /var/lib/apt/lists/*
docker dockerfile
add a comment |
I am trying to structure my docker image so it is small but I am not sure if this is a good pattern for keeping each layer small. Open for any recomendations?
The main points I am curious about are relating to the "update" and "rm" with each layer. Should i be doing it this way or is there a better method.
# our base image
FROM ubuntu
ENV DEBIAN_FRONTEND "noninteractive apt-get autoremove"
RUN apt-get update && apt-get install -y locales
&& locale-gen en_AU.UTF-8
&& dpkg-reconfigure locales
&& rm -rf /var/lib/apt/lists/*
ENV LANG en_AU.UTF-8
ENV LANGUAGE en_AU.UTF-8
ENV LC_ALL en_AU.UTF-8
ENV LC_CTYPE=en_AU.UTF-8
ENV TZ="Australia/Adelaide"
# networking and routing tools
RUN apt-get update && apt install -y
net-tools telnet dnsutils inetutils-traceroute
curl jq
postgresql redis-tools mongodb-clients
&& rm -rf /var/lib/apt/lists/*
# node libs for test scripts
RUN apt-get update && apt-get install -y
nodejs
npm
&& rm -rf /var/lib/apt/lists/*
docker dockerfile
Some suggestions: inherit from a specific tag of your base-image (e.g.ubuntu:18.04)
; merge your 3 RUN commands into one (comments like# node libs
can still be inserted between the lines if you like); merge your ENV declaration similarly to RUN (ENV <key>=<value> ...
). Generally your Dockerfile looks good, especially that you cleanup at the end of each RUN command.
– fab
Nov 23 '18 at 8:34
The "networking and routing tools" section at a glance is likely totally irrelevant to your application (telnet
?) and I'd delete it entirely. Consider replacing the whole thing withFROM node:8
.
– David Maze
Nov 23 '18 at 13:23
@fab so are you thinking there is no value in the layers separating the libs for test scripts from the core tools?
– donkeyx
Dec 4 '18 at 22:59
@donkeyx there might be cases where you'd want to do it for optimized caching, but in your case this it not the case: All those libs are just external dependencies which end up in your image eventually, so there's no benefit in having them in different layers. You might consider using docker-multistage-builds to keep your test-deps out of your runtime-image though.
– fab
Dec 5 '18 at 14:28
add a comment |
I am trying to structure my docker image so it is small but I am not sure if this is a good pattern for keeping each layer small. Open for any recomendations?
The main points I am curious about are relating to the "update" and "rm" with each layer. Should i be doing it this way or is there a better method.
# our base image
FROM ubuntu
ENV DEBIAN_FRONTEND "noninteractive apt-get autoremove"
RUN apt-get update && apt-get install -y locales
&& locale-gen en_AU.UTF-8
&& dpkg-reconfigure locales
&& rm -rf /var/lib/apt/lists/*
ENV LANG en_AU.UTF-8
ENV LANGUAGE en_AU.UTF-8
ENV LC_ALL en_AU.UTF-8
ENV LC_CTYPE=en_AU.UTF-8
ENV TZ="Australia/Adelaide"
# networking and routing tools
RUN apt-get update && apt install -y
net-tools telnet dnsutils inetutils-traceroute
curl jq
postgresql redis-tools mongodb-clients
&& rm -rf /var/lib/apt/lists/*
# node libs for test scripts
RUN apt-get update && apt-get install -y
nodejs
npm
&& rm -rf /var/lib/apt/lists/*
docker dockerfile
I am trying to structure my docker image so it is small but I am not sure if this is a good pattern for keeping each layer small. Open for any recomendations?
The main points I am curious about are relating to the "update" and "rm" with each layer. Should i be doing it this way or is there a better method.
# our base image
FROM ubuntu
ENV DEBIAN_FRONTEND "noninteractive apt-get autoremove"
RUN apt-get update && apt-get install -y locales
&& locale-gen en_AU.UTF-8
&& dpkg-reconfigure locales
&& rm -rf /var/lib/apt/lists/*
ENV LANG en_AU.UTF-8
ENV LANGUAGE en_AU.UTF-8
ENV LC_ALL en_AU.UTF-8
ENV LC_CTYPE=en_AU.UTF-8
ENV TZ="Australia/Adelaide"
# networking and routing tools
RUN apt-get update && apt install -y
net-tools telnet dnsutils inetutils-traceroute
curl jq
postgresql redis-tools mongodb-clients
&& rm -rf /var/lib/apt/lists/*
# node libs for test scripts
RUN apt-get update && apt-get install -y
nodejs
npm
&& rm -rf /var/lib/apt/lists/*
docker dockerfile
docker dockerfile
edited Nov 23 '18 at 4:31
asked Nov 23 '18 at 3:47
donkeyx
1638
1638
Some suggestions: inherit from a specific tag of your base-image (e.g.ubuntu:18.04)
; merge your 3 RUN commands into one (comments like# node libs
can still be inserted between the lines if you like); merge your ENV declaration similarly to RUN (ENV <key>=<value> ...
). Generally your Dockerfile looks good, especially that you cleanup at the end of each RUN command.
– fab
Nov 23 '18 at 8:34
The "networking and routing tools" section at a glance is likely totally irrelevant to your application (telnet
?) and I'd delete it entirely. Consider replacing the whole thing withFROM node:8
.
– David Maze
Nov 23 '18 at 13:23
@fab so are you thinking there is no value in the layers separating the libs for test scripts from the core tools?
– donkeyx
Dec 4 '18 at 22:59
@donkeyx there might be cases where you'd want to do it for optimized caching, but in your case this it not the case: All those libs are just external dependencies which end up in your image eventually, so there's no benefit in having them in different layers. You might consider using docker-multistage-builds to keep your test-deps out of your runtime-image though.
– fab
Dec 5 '18 at 14:28
add a comment |
Some suggestions: inherit from a specific tag of your base-image (e.g.ubuntu:18.04)
; merge your 3 RUN commands into one (comments like# node libs
can still be inserted between the lines if you like); merge your ENV declaration similarly to RUN (ENV <key>=<value> ...
). Generally your Dockerfile looks good, especially that you cleanup at the end of each RUN command.
– fab
Nov 23 '18 at 8:34
The "networking and routing tools" section at a glance is likely totally irrelevant to your application (telnet
?) and I'd delete it entirely. Consider replacing the whole thing withFROM node:8
.
– David Maze
Nov 23 '18 at 13:23
@fab so are you thinking there is no value in the layers separating the libs for test scripts from the core tools?
– donkeyx
Dec 4 '18 at 22:59
@donkeyx there might be cases where you'd want to do it for optimized caching, but in your case this it not the case: All those libs are just external dependencies which end up in your image eventually, so there's no benefit in having them in different layers. You might consider using docker-multistage-builds to keep your test-deps out of your runtime-image though.
– fab
Dec 5 '18 at 14:28
Some suggestions: inherit from a specific tag of your base-image (e.g.
ubuntu:18.04)
; merge your 3 RUN commands into one (comments like # node libs
can still be inserted between the lines if you like); merge your ENV declaration similarly to RUN (ENV <key>=<value> ...
). Generally your Dockerfile looks good, especially that you cleanup at the end of each RUN command.– fab
Nov 23 '18 at 8:34
Some suggestions: inherit from a specific tag of your base-image (e.g.
ubuntu:18.04)
; merge your 3 RUN commands into one (comments like # node libs
can still be inserted between the lines if you like); merge your ENV declaration similarly to RUN (ENV <key>=<value> ...
). Generally your Dockerfile looks good, especially that you cleanup at the end of each RUN command.– fab
Nov 23 '18 at 8:34
The "networking and routing tools" section at a glance is likely totally irrelevant to your application (
telnet
?) and I'd delete it entirely. Consider replacing the whole thing with FROM node:8
.– David Maze
Nov 23 '18 at 13:23
The "networking and routing tools" section at a glance is likely totally irrelevant to your application (
telnet
?) and I'd delete it entirely. Consider replacing the whole thing with FROM node:8
.– David Maze
Nov 23 '18 at 13:23
@fab so are you thinking there is no value in the layers separating the libs for test scripts from the core tools?
– donkeyx
Dec 4 '18 at 22:59
@fab so are you thinking there is no value in the layers separating the libs for test scripts from the core tools?
– donkeyx
Dec 4 '18 at 22:59
@donkeyx there might be cases where you'd want to do it for optimized caching, but in your case this it not the case: All those libs are just external dependencies which end up in your image eventually, so there's no benefit in having them in different layers. You might consider using docker-multistage-builds to keep your test-deps out of your runtime-image though.
– fab
Dec 5 '18 at 14:28
@donkeyx there might be cases where you'd want to do it for optimized caching, but in your case this it not the case: All those libs are just external dependencies which end up in your image eventually, so there's no benefit in having them in different layers. You might consider using docker-multistage-builds to keep your test-deps out of your runtime-image though.
– fab
Dec 5 '18 at 14:28
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440428%2fdocker-recomendations-on-docker-image-format-and-layers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440428%2fdocker-recomendations-on-docker-image-format-and-layers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Some suggestions: inherit from a specific tag of your base-image (e.g.
ubuntu:18.04)
; merge your 3 RUN commands into one (comments like# node libs
can still be inserted between the lines if you like); merge your ENV declaration similarly to RUN (ENV <key>=<value> ...
). Generally your Dockerfile looks good, especially that you cleanup at the end of each RUN command.– fab
Nov 23 '18 at 8:34
The "networking and routing tools" section at a glance is likely totally irrelevant to your application (
telnet
?) and I'd delete it entirely. Consider replacing the whole thing withFROM node:8
.– David Maze
Nov 23 '18 at 13:23
@fab so are you thinking there is no value in the layers separating the libs for test scripts from the core tools?
– donkeyx
Dec 4 '18 at 22:59
@donkeyx there might be cases where you'd want to do it for optimized caching, but in your case this it not the case: All those libs are just external dependencies which end up in your image eventually, so there's no benefit in having them in different layers. You might consider using docker-multistage-builds to keep your test-deps out of your runtime-image though.
– fab
Dec 5 '18 at 14:28