For production deployment, I don't want shared volumes. So, I have an override file but this does not remove the volumes.
Is there a way to remove shared volumes in an override file? I'd like to avoid having an override just for development, because that seems clunky to use.
This is my docker-compose.yml
:
version: '2' # other services defined here services: web: build: context: . # other configuration volumes: - .:${APP_DIR}
And my docker-compose.prod.yml
:
version: '2' services: web: volumes: [] restart: always
Stops containers and removes containers, networks, volumes, and images created by up .
Docker Compose offers you the ability to not only compose a collection of Docker services via a yaml configuration doc, but to override this configuration based on the environment to which it is being deployed. Each docker-compose. yml file can (and should) have a corresponding docker-compose.
Docker-compose command doesn't override Dockerfile CMD.
There are two ways where you can create a volume, bind mounts and volumes. Whichever you choose, once you have set up a volume to the folder where the data is stored in the container, if you do a docker-compose down , and then a docker-compose up , your data will not be erased and it will become persistent.
I'm assuming you want to use docker-compose up
to start the development version, and have a second config file to extend it for production.
If you want to make sure to override volumes completely, use a third config file, docker-compose.override.yml
. Put all your volume definitions for development in there.
docker-compose up
extends the base config with this file by default. But when you do something like docker-compose -f docker-compose.yml -f production.yml
, the docker-compose.override.yml
file won't be loaded, and you'll get only the volumes from the production file.
When merging a list entry in docker-compose
, it adds new maps but doesn't remove existing volume mappings.
You can implement this by either making dev have the override file, or up to version 2.1 you can extend a common docker file rather than applying overrides which lets to devs point to a single file.
This could be your docker-compose.yml:
version: '2' # other services defined here services: web: extends: file: docker-compose.prod.yml service: web build: context: . restart: no volumes: - .:${APP_DIR}
And your docker-compose.prod.yml would contain all the common configuration and prod settings:
version: '2' services: web: # other configuration restart: always
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