How to name a volume using docker-compose.yml?

I am new to Docker and I am trying to figure out how to set the name of the created data volume. Currently, the directory is automatically called the long hash in / var / libs / docker, which is far from user-friendly.

I am trying to set up a development environment for MODX, as shown here: https://github.com/modxcms/docker-modx

Currently, my docker-compose.yml file looks like this:

web: image: modx links: - db:mysql ports: - 80:80 db: image: mysql environment: MYSQL_ROOT_PASSWORD: example ports: - 3306:3306 command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION myadmin: image: phpmyadmin/phpmyadmin links: - db:db ports: - 8080:8080 

This works fine, but I'm not sure how to name the data volume that I would edit directly using my IDE.

(As a side question, do I need to create it in / var / libs / docker? Or is there a way to install it in a directory in my home folder?)

Update: Thanks to the help of @juliano, I updated the docker-compose.yml file to:

 version: '2' services: web: image: modx volumes: - html:/home/muzzstick/dev/modxdev links: - db:mysql ports: - 80:80 db: image: mysql environment: MYSQL_ROOT_PASSWORD: example ports: - 3306:3306 command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION myadmin: image: phpmyadmin/phpmyadmin links: - db:db ports: - 8080:8080 volumes: html: external: false 

Unfortunately, it looks like the web container is not running. db and myadmin containers show that they are working fine. There were no errors ... if I type docker start docker_web_1 , it will appear, but docker ps -a shows that it exited as soon as it started.

Update 2

Running docker-compose up -d without any problems. But then, as you can see below, the web container exits as soon as it is created.

  CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a1dd6d8ac94e modx "/entrypoint.sh apach" 10 seconds ago Exited (1) 5 seconds ago docker_web_1 ee812ae858dc phpmyadmin/phpmyadmin "/run.sh phpmyadmin" 10 seconds ago Up 5 seconds 80/tcp, 0.0.0.0:8080->8080/tcp docker_myadmin_1 db496134e0cf mysql "docker-entrypoint.sh" 11 seconds ago Up 10 seconds 0.0.0.0:3306->3306/tcp docker_db_1 

Update 3 OK The error logs for this container show:

 error: missing MODX_DB_HOST and MYSQL_PORT_3306_TCP environment variables Did you forget to --link some_mysql_container:mysql or set an external db with -e MODX_DB_HOST=hostname:port? 

This error occurs from https://github.com/modxcms/docker-modx/blob/master/apache/docker-entrypoint.sh#L15-L20

Could it be something like a link, handled differently in version 2 for docker?

+5
source share
2 answers

To create a named data volume using version 2 for linking files , you will have a dedicated area:

 version: '2' services: db: image: postgres volumes: - amazingvolume:/var/lib/postgresql/data volumes: amazingvolume: external: true 

So, you can define the name of the volume (amazingvolume) if it is external or not and under your service (db in this example) you can determine which directory you are going to mount.

+8
source

Just search the docker documentation for hosted volumes:

 version: '2' services: web: image: modx environment: - MYSQL_PORT_3306_TCP=3306 - MODX_DB_HOST=mysql:3306 volumes: - /home/muzzstick/dev/modxdev/html:/var/www/html links: - db:mysql ports: - 80:80 db: image: mysql environment: MYSQL_ROOT_PASSWORD: example ports: - 3306:3306 command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION myadmin: image: phpmyadmin/phpmyadmin links: - db:db ports: - 8080:8080 

Change /var/www/html to the directory where the html files will be inside the container. And also create a directory on the left of your host and give read permission to all users.

Yours faithfully

+1
source

Source: https://habr.com/ru/post/1261788/


All Articles