Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace volumes_from in docker-composer v3

Tags:

I want to know the equivalent of the configuration below to suit version 3 of docker-composer.yml! volumes_from is no longer valid so am I supposed to skip the data volume and replace it with top level volumes ?

version: '2' services:    php:     build: ./docker-files/php-fpm/.     volumes_from:       - data     working_dir: /code     links:       - mysql    nginx:     image: nginx:latest     ports:       - "80:80"     volumes:       - ./nginx/default.conf:/etc/nginx/conf.d/default.conf     volumes_from:       - data     links:       - php    data:     image: tianon/true     volumes:       - .:/code 
like image 706
prometheus Avatar asked Feb 15 '17 08:02

prometheus


People also ask

Does Docker compose replace Dockerfile?

No, Dockerfile instructs Docker how to build your image(s). Docker Compose instructs Docker how to run your image(s). Thx, so I have to make a dockerfile just to have the copy command ?

How do I recreate a docker compose container?

If you want to force Compose to stop and recreate all containers, use the --force-recreate flag. If the process encounters an error, the exit code for this command is 1 . If the process is interrupted using SIGINT (ctrl + C) or SIGTERM , the containers are stopped, and the exit code is 0 .

Is Docker compose deprecated?

Following the deprecation of Compose on Kubernetes, support for Kubernetes in the stack and context commands in the docker CLI is now marked as deprecated as well.


1 Answers

By default named volumes allow you to share data between containers. But it is some troubles with storing data in the same place on the host machine after restarting containers. But we can use local-persist docker plugin for fix it.

For migration to version 3 you need

1) install local-persist docker plugin (if you want to store volumes data to the particular place on the host machine)

2) modify docker-compose.yml

version: '3' services:    php:     build: ./docker-files/php-fpm/.     volumes:       - data:/code     working_dir: /code     links:       - mysql    nginx:     image: nginx:latest     ports:       - "80:80"     volumes:       - ./nginx/default.conf:/etc/nginx/conf.d/default.conf     volumes:       - data:/code     links:       - php    data:     image: tianon/true     volumes:       - data:/code  # If you use local persist plugin volumes:   data:     driver: local-persist     driver_opts:       mountpoint: /path/on/host/machine/  # Or If you dont want using local persist plugin volumes:   data: 

Also you can store volumes data to the host machine with this volumes section:

volumes:   data:     external: true #< it means store my data to the host machine 

But you can't specify path for this volume on host machine

like image 69
Bukharov Sergey Avatar answered Oct 26 '22 05:10

Bukharov Sergey