Inside Dockerfile I have this
......
......
RUN \\
chown root:root /opt \\
&& chown wasadmin:mqm /opt/adp \\
&& chown wasadmin:mqm -R /opt/adp/pids/ \\
&& chown wasadmin:mqm -R /var/scripts/
.......
.......
Instead fo the above I want to put
......
......
COPY scripts/myscript.sh /tmp
RUN chmod 700 /tmp/myscript.sh && /tmp/myscript.sh
.......
.......
The /tmp/myscript.sh
has the same contents as that of first RUN command, aka
chown root:root /opt
chown wasadmin:mqm /opt/adp
chown wasadmin:mqm -R /opt/adp/pids/
chown wasadmin:mqm -R /var/scripts/
By doing the second approach will it reduce layers ?
CodePudding user response:
As a practical matter, you will notice absolutely no difference (unless your Dockerfile is very very large) and if the script is substantial you might find it easier to edit and debug the separate script. If you're considering this path, there's nothing wrong with it.
At a technical level, yes, the "classic" Docker builder will create one additional layer with the extra script. (The newer BuildKit builder has some optimization capabilities and might behave differently.) Unless you're hitting Docker's internal layer limit or there are build-cache considerations this doesn't really mean anything.
CodePudding user response:
Thanks to Mr. David Maze for his answer.
A few more clarifications are requested.
My confusion is that the script file aka the one I run after I copy looks like this
chown root:root /opt
chown wasadmin:mqm /opt/adp
chown wasadmin:mqm -R /opt/adp/pids/
chown wasadmin:mqm -R /var/scripts/
You see inside the script there are 4 sep steps and I don't have to put \ there and it is regular bash script.
In the above script, is each command considered a layer or the line
RUN \\
chmod 700 /tmp/myscript.sh && /tmp/myscript.sh
considered one layer ?