2015-10-21 4 views
1

Я пытаюсь создать изображение путем изменения некоторых файлов в существующем изображении. Однако файлы не изменяются командами RUN. Мой файл докеров -Невозможно изменить файлы в контейнере из docker

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 

Базовый образ из общедоступного хранилища докеров. Когда я запускаю его, я получаю следующие выходные данные

$ 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 

ADD . . сработал, а passwords.txt и queues.xml как показать в ls. whoami показывает, что текущий пользователь является root, поэтому проблем с разрешениями не должно быть.

Однако существующие файлы не изменяются. Если я запустил изображение, но использовал bash в качестве команды запуска (см. Ниже), ни один из файлов не имеет текущей даты, хотя файл, который был заменен на существующий файл, исчез. Если я вставляю команду sed в оболочку, она обновляет файл.

$ docker run -it effd394fc02f bash 
[email protected]:/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 
[email protected]:/var/lib/artemis/bin# cd ../etc 
[email protected]:/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 

Почему эти файлы не изменяются командами run?

ответ

1

Актуальная проблема была связана с тем, как было построено базовое изображение. Если вы запустите docker history --no-trunc vromero/activemq-artemis, вы видите эти команды (среди прочих):

<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 состояния

Примечание: Если какие-либо шаги сборки изменить данные в объеме после того, как было объявлено, эти изменения будут отбрасываются.

Это означает, что конфигурация в базовом изображении заблокирована.

Я решил проблему, создав свой собственный файл docker на основе вывода команды history без строк volume.

+0

Это кажется более точным, чем мой ответ;) +1 – VonC

+0

Я специально использовал VOLUME, чтобы люди могли продлить изображение без расширения, но, видимо, я заблокировал людей, пытающихся расширить. Я займусь этим. Тем не менее, я не смог вытащить запрос или предложить изменения, я буду счастлив слить. . Если вам просто нужно изменить имя пользователя и пароль, рассмотрите следующие параметры: https://github.com/vromero/activemq-artemis-docker#setting-username-and-password –

+0

@ VíctorRomero Спасибо. Мне нужно было сделать больше изменений, чем просто имя пользователя и пароль. Я закончил тем, что создал файл докеров, который был вашей копией, удалив инструкции VOLUME, а затем внес необходимые изменения. Мне непонятно, как вы могли бы разоблачить эти каталоги и все-таки позволить людям вносить изменения в расширяющийся файл докеров. –

1

Не полный ответ, но по крайней мере ключ: вы не меняете точку входа встроенного изображения.
Это означает, что изображение все еще будет выполнять один из vromero/activemq-artemis, который, по словам его Dockerfile является:

ENTRYPOINT ["/docker-entrypoint.sh"] 

И docker-entrypoint.sh может сбросить некоторые изменения на docker run.

+0

Я сомневаюсь, что это актуально. Если вы посмотрите на вывод докера, выполните шаг 4 'RUN' 'rm -f/var/lib/artemis/etc/artemis-users.properties'. Шаг 5 'RUN' 'ls -l/var/lib/artemis/etc', в котором показан файл, который попытался удалить предыдущий шаг. Точка входа не может отменить изменение, поскольку оно было отменено или не произошло задолго до того, как точка входа используется. –

+0

@TroyDaniels Я согласен. Я имел в виду это как отправную точку: просто проверить, попробовать и переопределить точку входа, чтобы быть уверенным, что это не преступник. – VonC

0

В файле Dockerfile есть две команды RUN.

Вы работаете в этом: RUN <command> (команда запускается в оболочке - /bin/sh -c (форма оболочки)

Другой заключается в следующем: RUN ["executable", "param1", "param2"] (Exec форма)

Попробуйте это:

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"] 
+0

Есть ли причина, почему это может сработать, когда другая форма не работает? –

+0

проверьте документацию - https://docs.docker.com/reference/builder/#run. 'В отличие от формы оболочки, форма exec не вызывает командную оболочку.' Кроме того, '/ bin/sh' отличается от'/bin/bash' или других оболочек. – bdparrish

Смежные вопросы