I have a docker-compose.yml
configuration. In one of the containers there is a Tomcat server and it has some default .war
file deployed in webapps
directory.
I want to have an ability to pass (override) the war
archive to be deployed by some which resides on the host machine. I think the best would be to have ability somehow switch / override starting docker-compose
: as a default, I want to run the webapp (war
file) which is inside the container, but I want to have a possibility to mount a directory from my host (for example during development / debugging) if need be.
Currently, I have the following line in my docker-compose.yml
, which is commented out if I need the default.
volumes: # By default, there is the latest version of the application already present in the container # If you want to provider the container with your own .war file, uncomment the following line # - ./application/webapps:/usr/local/tomcat/webapps
Is there a better way how to achieve that?
When building an image, you can't mount a volume. However, you can copy data from another image! By combining this, with a multi-stage build, you can pre-compute an expensive operation once, and re-use the resulting state as a starting point for future iterations.
But, if you do need to add a volume to a running container, you can use docker commit to make a new image based on that container, and then clone it with the new volume. Then, you can run the new image, replacing the old image with the cloned one.
The most notable difference between the two options is that --mount is more verbose and explicit, whereas -v is more of a shorthand for --mount . It combines all the options you pass to --mount into one field. On the surface, both commands create a PostgreSQL container and set a volume to persist data.
Since extend
has been removed in version 3 there's a new way of overriding settings by providing multiple -f params where the next file extends the previous config
The docs are mixed between versions https://docs.docker.com/compose/extends/#multiple-compose-files
i.e. to run in development mode
docker-compose -f docker-compose.yml -f docker-compose.dev.yml
Where docker-compose.yml
contains the full config and docker-compose.dev.yml
only adds a volume
services: serviceA: volumes: -.:/usr/local/abc/service
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With