I am attempting to build an imaging by modifying some of the files in an existing image. However, the files are not changed by RUN
commands. My dockerfile is
FROM vromero/activemq-artemis
ADD . .
RUN ls
RUN whoami
# Overwrite existing password file. The existing file is invulnerable, and
# cannot be modified by docker. I have no idea why.
RUN rm -f /var/lib/artemis/etc/artemis-users.properties
RUN ls -l /var/lib/artemis/etc
RUN mv passwords.txt /var/lib/artemis/etc/artemis-users.properties
RUN cat /var/lib/artemis/etc/artemis-users.properties
RUN touch /var/lib/artemis/etc/touch-test
# Add the predefined queues
RUN sed -i.bak '/<core/r queues.xml' /var/lib/artemis/etc/broker.xml
# EOF
The base image is from the public docker repository. When I run it, I get the following output
$ docker build .
Sending build context to Docker daemon 4.608 kB
Step 0 : FROM vromero/activemq-artemis
---> 4e0f54c798cc
Step 1 : ADD . .
---> 3efde5a1fdea
Removing intermediate container c8621adc900b
Step 2 : RUN ls
---> Running in 5c5dca9449da
Dockerfile
artemis
artemis-service
passwords.txt
queues.xml
---> 22c541f98339
Removing intermediate container 5c5dca9449da
Step 3 : RUN whoami
---> Running in f11fcd2e2c5b
root
---> 15ee9aeb4c15
Removing intermediate container f11fcd2e2c5b
Step 4 : RUN rm -f /var/lib/artemis/etc/artemis-users.properties
---> Running in ab4383f0bb91
---> 10877bdb08ee
Removing intermediate container ab4383f0bb91
Step 5 : RUN ls -l /var/lib/artemis/etc
---> Running in a5669c8808e8
total 24
-rw-r--r-- 1 artemis artemis 959 Oct 4 05:40 artemis-roles.properties
-rw-r--r-- 1 artemis artemis 968 Oct 4 05:40 artemis-users.properties
-rwxrwxr-x 1 artemis artemis 1342 Oct 4 05:40 artemis.profile
-rw-r--r-- 1 artemis artemis 1302 Oct 4 05:40 bootstrap.xml
-rw-r--r-- 1 artemis artemis 4000 Oct 4 05:40 broker.xml
-rw-r--r-- 1 artemis artemis 2203 Oct 4 05:40 logging.properties
---> 02e3acc58653
Removing intermediate container a5669c8808e8
Step 6 : RUN mv passwords.txt /var/lib/artemis/etc/artemis-users.properties
---> Running in 68000aa34f6b
---> ec057d5adc67
Removing intermediate container 68000aa34f6b
Step 7 : RUN cat /var/lib/artemis/etc/artemis-users.properties
---> Running in 934a36d8c4d1
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
apollo=ollopaehcapa ---> ca1bad8a8903
Removing intermediate container 934a36d8c4d1
Step 8 : RUN touch /var/lib/artemis/etc/touch-test
---> Running in cb931c5cfcd1
---> 6961b4fcde75
Removing intermediate container cb931c5cfcd1
Step 9 : RUN sed -i.bak '/<core/r queues.xml' /var/lib/artemis/etc/broker.xml
---> Running in a829642b29ab
---> effd394fc02f
Removing intermediate container a829642b29ab
Successfully built effd394fc02f
The ADD . .
has worked, as passwords.txt and queues.xml both show up in the ls
. whoami
shows that the current user is root, so there should be no permissions problems.
However, the existing files are not changed. If I run the image but use bash
as the start command (see below), none of the files have a current date, although the file that was mv
'ed to replace an existing file is gone. If I paste the sed
command into the shell, it does update the file.
$ docker run -it effd394fc02f bash
root@51d1cc0a94cb:/var/lib/artemis/bin# ls -l
total 16
-rw-r--r-- 1 root root 543 Oct 21 22:12 Dockerfile
-rwxrwxr-x 1 artemis artemis 3416 Oct 4 05:40 artemis
-rwxrwxr-x 1 artemis artemis 3103 Oct 4 05:40 artemis-service
-rw-r--r-- 1 root root 329 Oct 21 22:18 queues.xml
root@51d1cc0a94cb:/var/lib/artemis/bin# cd ../etc
root@51d1cc0a94cb:/var/lib/artemis/etc# ls -l
total 24
-rw-r--r-- 1 artemis artemis 959 Oct 4 05:40 artemis-roles.properties
-rw-r--r-- 1 artemis artemis 968 Oct 4 05:40 artemis-users.properties
-rwxrwxr-x 1 artemis artemis 1342 Oct 4 05:40 artemis.profile
-rw-r--r-- 1 artemis artemis 1302 Oct 4 05:40 bootstrap.xml
-rw-r--r-- 1 artemis artemis 4000 Oct 4 05:40 broker.xml
-rw-r--r-- 1 artemis artemis 2203 Oct 4 05:40 logging.properties
Why are these files not being changed by the run
commands?
The actual problem was related to how the base image was built. If you run docker history --no-trunc vromero/activemq-artemis
, you see these commands (among others):
<id> 6 weeks ago /bin/sh -c #(nop) VOLUME [/var/lib/artemis/etc] 0 B
<id> 6 weeks ago /bin/sh -c #(nop) VOLUME [/var/lib/artemis/tmp] 0 B
<id> 6 weeks ago /bin/sh -c #(nop) VOLUME [/var/lib/artemis/data] 0 B
The Dockerfile volume
documentation states
Note: If any build steps change the data within the volume after it has been declared, those changes will be discarded.
This means that the configuration in the base image is locked.
I solved my problem by creating my own dockerfile based on the output of the history command, without the volume
lines.