Reputation: 107
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 ?
Upvotes: 1
Views: 403
Reputation: 158908
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.
Upvotes: 1