I've 4 images which they do not share the same basic image :
image1 : FROM openjdk:8
image2 : FROM mongo:3.6
image3 : FROM ssh
image4 : FROM ubuntu
But at some point I've to execute the same commands on all of them, ex:
RUN useradd -s /bin/bash -p $(openssl passwd -1 user) -d /home/user -m -G sudo user
USER user
WORKDIR /home/user
RUN mkdir -p /home/user/.ssh/ && \
chmod 0700 /home/user/.ssh && \
touch /home/user/.ssh/authorized_keys && \
chmod 600 /home/user/.ssh/authorized_keys && \
touch /home/user/.ssh/config && \
chmod 600 /home/user/.ssh/config
COPY ssh-keys/ /keys/
RUN cat /keys/id_rsa.pub >> /home/user/.ssh/authorized_keys
RUN cat /keys/config >> /home/user/.ssh/config
and having the same directories structure :
image1
--->ssh-keys
------>config
------>id_rsa
------>id_rsa.pub
--->Dockerfile
image2
--->ssh-keys
------>config
------>id_rsa
------>id_rsa.pub
--->Dockerfile
image3
--->ssh-keys
------>config
------>id_rsa
------>id_rsa.pub
--->Dockerfile
image4
--->ssh-keys
------>config
------>id_rsa
------>id_rsa.pub
--->Dockerfile
Is there a way to remove this duplications ?