skip to Main Content

I am trying to create a dockerfile that will have image 1 and image 2 pulled from dockerhub. It seems that second image is overriding the changes of first image. How to handle this scenario.

FROM clamav/clamav:1.1
COPY clamd.conf /etc/clamav
EXPOSE 3310/tcp
RUN echo $(ls -ltrh var/log) # this is showing the appname as the result
FROM fluent/fluentd:v1.14-1
COPY fluent.conf /fluentd/etc/
RUN echo $(ls -ltrh var/log) # now this is showing no result, empty directory.

2

Answers


  1. Chosen as BEST ANSWER

    @pgossa, what about this one. maybe not a good approach as you mentioned but will it work? just a thought.

    FROM fluent/fluentd:v1.14-1 AS fluentd
    COPY fluent.conf /fluentd/etc/
    
    FROM clamav/clamav:1.1
    COPY clamd.conf /etc/clamav
    COPY --from=fluentd /fluentd /fluentd
    EXPOSE 3310/tcp
    

  2. The second FROM instructions is pulling a new image(fluentd) which delete the changes made in your first one(clamav).
    If you want to create 2 images then you need 2 dockerfile.
    And so split your file in two.

    If you are planning on having only one image containing both applications, your dockerfile should look something like this:

    FROM fluentd:v1.16.0-debian-1.0
    COPY fluent.conf /fluentd/etc/
    RUN apt install clamav clamav-daemon -y
    COPY clamd.conf /etc/clamav
    
    EXPOSE 3310/tcp
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search