-1

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?

KitKarson
  • 5,211
  • 10
  • 51
  • 73

1 Answers1

1

Ok.. I was able to reduce the size by 300MB with below statement

COPY --chown=app:app dirA dirA
COPY --chown=app:app dirB dirB
KitKarson
  • 5,211
  • 10
  • 51
  • 73