Docker composes a volume named: find volume on the host machine

I have docker-compose.yml:

version: '2' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress volumes: db_data: 

When I run this docker-compose up -d and then do docker inspect -f '{{ (index .Mounts 0).Source }}' ef8be254a08b for the db container used to get a source that indicates the location of the volume on the host, I I always get "There is no such file or directory" if I ls directory ( ls /var/lib/docker/volumes/test_db_data/_data: No such file or directory ). How can I get a real location for volume?

+6
source share
1 answer

So, I got the answer. The main thing is that Docker on Mac is still running inside the VM . Thus, the system paths still refer to the VM, not your Mac. All containers are stored in the VM and located in ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

To enter virtual machine use:

 screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty 

Then you can see the contents of the source folder specified in docker inspect {container_id} :

 ls /var/lib/docker/volumes/test_db_data/_data 
+2
source

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


All Articles