The image I am using is quay.io/artemiscloud/activemq-artemis-broker
.
My docker-compose.yml
is:
version: "3"
services:
artemis:
image: quay.io/artemiscloud/activemq-artemis-broker
environment:
AMQ_USER: admin
AMQ_PASSWORD: password
ports:
- "5672:5672"
- "61616:61616"
- "8161:8161"
networks:
- backend
networks:
backend:
driver: bridge
When I run docker-compose up
, the container can successfully run.
I then go inside the container (container id 5905b9
):
~ docker exec -it 5905b9 bash
[jboss@5905b996368e ~]$ pwd
/home/jboss
I can see that the default path right after get in is /home/jboss
.
I also verified that there is /home/jboss/broker/etc/
directory inside the container (by default):
[jboss@5905b996368e ~]$ pwd
/home/jboss
[jboss@5905b996368e ~]$ ls
broker
[jboss@5905b996368e ~]$ ls ./broker/etc/
artemis-roles.properties artemis.profile bootstrap.xml jolokia-access.xml login.config
artemis-users.properties broker.xml log4j2.properties management.xml
I also verified that there is /home/jboss/broker/bin/artemis
file inside container:
[jboss@5905b996368e ~]$ ls ./broker/bin/
artemis artemis-service
(Please keep above verification in mind, it relates to the failure log below)
After verified these things. I stoped the container by docker-compose down
.
Then, I modified my docker-compose.yml
to mount a local file on my host ./config/my.json
to the container path /home/jboss/broker/etc/my.json
:
version: "3"
services:
artemis:
image: quay.io/artemiscloud/activemq-artemis-broker
environment:
AMQ_USER: admin
AMQ_PASSWORD: password
# mount local file to container path
volumes:
- ./config/my.json:/home/jboss/broker/etc/my.json
ports:
- "5672:5672"
- "61616:61616"
- "8161:8161"
networks:
- backend
networks:
backend:
driver: bridge
Then, I run the docker-compose up
again . However, this time, the container starting failed. The log shows this message:
2024-03-03 18:51:40 /opt/amq/bin/launch.sh: line 49: /home/jboss/broker/bin/artemis: No such file or directory
2024-03-03 18:51:40 Running Broker
The logs basically says the launch.sh
tries to access file /home/jboss/broker/bin/artemis
but there isn't such file. But like I verified above, this file DOES exists!
Why after modified docker-compose.yml
to mount my local file to that specific container path, the ActiveMQ Artemis container stopped working & throw that weird message??
====More debugging info====
I also noticed if I change the mount path to :
volumes:
- ./config/my.json:/home/jboss/my.json
Then the container can run successfully, I can see my.json
in that container path:
[jboss@6af16611b85e ~]$ ls
broker my.json
But I need to have it inside /home/jboss/broker/etc/
.
====== update to run container with root user ====
Thanks for the answer from @Domenico Francesco Bruscino, I tried to run the container with root user:
version: "3"
services:
artemis:
user: "root"
image: quay.io/artemiscloud/activemq-artemis-broker
environment:
AMQ_USER: admin
AMQ_PASSWORD: password
AMQ_RESET_CONFIG: true
volumes:
# mount local file to container path as a new file works well!
- ./config/my.json:/home/jboss/broker/etc/my.json
# mount local file to overwrite a file in container path fails!
- ./config/login.config:/home/jboss/broker/etc/login.config
ports:
- "5672:5672"
- "61616:61616"
- "8161:8161"
networks:
- backend
networks:
backend:
driver: bridge
Mounting local file as a new file in the container path /home/jboss/broker/etc/my.json
works well!
But mounting local file that overwrite an existing file in the same path fails with error:
2024-03-04 22:30:59 Exception in thread "main" java.io.FileNotFoundException: broker/etc/login.config (Permission denied)
The launch.sh
script of quay.io/artemiscloud/activemq-artemis-broker
container image doesn't create a broker instance when the broker
directory already exist, see https://github.com/artemiscloud/activemq-artemis-broker-image/blob/1.0.25/modules/activemq-artemis-install/added/launch.sh#L17
You need to run the container with the root user and to set the enviornment variable AMQ_RESET_CONFIG
to true
to force artemis to create a broker instance when the broker
directory already exist, i.e.
version: "3"
services:
artemis:
user: "root"
image: quay.io/artemiscloud/activemq-artemis-broker
environment:
AMQ_USER: admin
AMQ_PASSWORD: password
AMQ_RESET_CONFIG: true
# mount local file to container path
volumes:
- ./config/my.json:/home/jboss/broker/etc/my.json
ports:
- "5672:5672"
- "61616:61616"
- "8161:8161"
networks:
- backend
networks:
backend:
driver: bridge
Alternatively, you could pass a full broker instance when you need to add custom files to the /home/jboss/broker
directory.
To avoid to run the container with the root user you can overwrite the container command, i.e.
version: "3"
services:
artemis:
image: quay.io/artemiscloud/activemq-artemis-broker
environment:
AMQ_USER: admin
AMQ_PASSWORD: password
AMQ_RESET_CONFIG: true
# mount local file to container path
volumes:
- ./config/my.json:/config/my.json
command: bash -c 'mkdir -p /home/jboss/broker/etc && cp /config/my.json /home/jboss/broker/etc/ && /opt/amq/bin/launch.sh'
ports:
- "5672:5672"
- "61616:61616"
- "8161:8161"
networks:
- backend
networks:
backend:
driver: bridge