Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't overwrite file in docker compose

I'm using docker compose to set up a payara server and need to overwrite the domain.xml file. I'm currently doing it through

volumes: - './domain.xml:/opt/payara41/glassfish/domains/domain1/config/domain.xml' but when i compose it with docker-compose up it keeps saying that it could not rename domain.xml to domain.xml.bak. Is there any way i can get permissions to overwrite it or make sure the rename works ?

like image 709
Wouter Avatar asked Jun 06 '17 12:06

Wouter


1 Answers

Something like this should work:

command: sh -c 'cp /tmp/domain.xml /opt/payara41/glassfish/domains/domain1/config/domain.xml && YOUR_PREVIOUS_COMMAND'
volumes:
   - ./domain.xml:/tmp/domain.xml

Or edit your current command (or CMD) if it's a script, prepending the copy.


Edit: This alternative is very handy and elegant.

command: sh /run-from-compose.sh
volumes:
   - ./domain.xml:/tmp/domain.xml
   - ./run-from-compose.sh:/run-from-compose.sh

run-from-compose.sh:

#!/bin/sh
cp /tmp/domain.xml /opt/payara41/glassfish/domains/domain1/config/domain.xml

YOUR_PREVIOUS_COMMAND

You don't need to modify the image, just mount a custom script that acts as command.

like image 196
Robert Avatar answered Nov 14 '22 15:11

Robert