我使用的图像是
quay.io/artemiscloud/activemq-artemis-broker
。
在我的
docker-compose.yml
中,我使用 root 用户运行容器:
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
将本地文件作为新文件挂载到容器路径中
/home/jboss/broker/etc/my.json
效果很好!
但是安装本地文件以覆盖同一路径中的现有文件失败并出现错误:
2024-03-04 22:30:59 Exception in thread "main" java.io.FileNotFoundException: broker/etc/login.config (Permission denied)
我已验证:
我已经验证容器内有
/home/jboss/broker/etc/
目录(默认情况下)并且路径内有 login.config
文件,我尝试覆盖该文件:
[jboss@5905b996368e ~]$ pwd
/home/jboss
[jboss@5905b996368e ~]$ ls
broker
[jboss@5905b996368e ~]$ ls ./broker/etc/
... login.config
...
那么,如何在主机上挂载本地文件
./config/login.config
来覆盖容器路径中的文件/home/jboss/broker/etc/login.config
??
仅适用于
loging.config
的简单解决方案是通过设置系统属性 loging.config
将代理指向自定义 ava.security.auth.login.config
路径,即
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
更通用的解决方案需要覆盖容器命令,即
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
或者,当您需要覆盖 /home/jboss/broker 目录中的实例文件时,您可以传递完整的代理实例。