Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intentionally removing volumes in override docker-compose files

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 
like image 419
Rushy Panchal Avatar asked Mar 25 '17 18:03

Rushy Panchal


People also ask

Does Docker compose delete volumes?

Stops containers and removes containers, networks, volumes, and images created by up .

What is the use of Docker compose override?

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.

Does Docker compose override Dockerfile?

Docker-compose command doesn't override Dockerfile CMD.

Do Docker compose volumes persist?

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.


2 Answers

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.

like image 121
Jonathan Dupré Avatar answered Sep 24 '22 17:09

Jonathan Dupré


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 
like image 25
BMitch Avatar answered Sep 24 '22 17:09

BMitch