Mounting a local file to overwrite a default file in the container of ActiveMQ Artemis

33 Views Asked by At

The image I am using is quay.io/artemiscloud/activemq-artemis-broker.

In my docker-compose.yml, I 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 to 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)

What I have verified:

I have verified that there is /home/jboss/broker/etc/ directory inside the container (by default) and inside the path there is login.config file which I try to overwrite:

[jboss@5905b996368e ~]$ pwd
/home/jboss

[jboss@5905b996368e ~]$ ls
broker

[jboss@5905b996368e ~]$ ls ./broker/etc/
...  login.config
...

So, how can I mount my local file ./config/login.config on host to overwrite the file in container path /home/jboss/broker/etc/login.config??

1

There are 1 best solutions below

0
On

A simple solution that works only for loging.config is to point the broker to a custom loging.config path by setting the system property ava.security.auth.login.config, i.e.

version: "3"
services:
  artemis:
    user: "root"
    image: quay.io/artemiscloud/activemq-artemis-broker
    environment:
      AMQ_USER: admin
      AMQ_PASSWORD: password
      JAVA_ARGS_APPEND: "-Djava.security.auth.login.config=/opt/amq/login.config"

    
    volumes:
      # mount local file to overwrite a file in container path fails!
      - ./config/login.config:/opt/amq/login.config

    ports:
      - "5672:5672"
      - "61616:61616"
      - "8161:8161"
    networks:
      - backend

networks:
  backend:
    driver: bridge

A more generic solution requires to overwrite the container command, i.e.

version: "3"
services:
  artemis:
    user: "root"
    image: quay.io/artemiscloud/activemq-artemis-broker
    environment:
      AMQ_USER: admin
      AMQ_PASSWORD: password

    
    volumes:
      # mount local file to overwrite a file in container path fails!
      - ./config/login.config:/opt/amq/etc/login.config

    command: bash -c "sed 's~  configure~  configure\n  cp --recursive /opt/amq/etc/* /home/jboss/broker/etc~' /opt/amq/bin/launch.sh | source /dev/stdin"

    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 overwrite instance files in the the /home/jboss/broker directory.