I have a dockerfile which is based on openjdk:8u151-jre-alpine3.7
which works perfectly fine. The containers used to run as root user.
I wanted to modify it to use an user called 'app'.
# Add new user
RUN adduser -D -u 1000 app
ENV USER_HOME=/home/app
WORKDIR $USER_HOME
then i have few COPY commands
COPY dirA dirA
COPY dirB dirB
in the image all these dirA and dirB owned by root. so, i add chwon statement.
adding below statement in the dockerfile increases the size by 300MB
.
# chown all the files by app user
RUN chown -R app:app $USER_HOME
USER app
What is really going on? How to reduce the size by owning the files as app user?