Docker Named Volume location Mac

吃可爱长大的小学妹 提交于 2019-12-07 18:08:36

问题


I'm using Docker for Mac 1.12.1 and have a docker compose file which starts wordpress and mysql services

Compose file

version: '2'
services:
  db:
    container_name: mysql_db
    image: mysql:5.7
    volumes:
      - "./.data/db:/var/lib/mysql"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    container_name: wordpress
    depends_on:
      - db
    image: wordpress:latest
    links:
      - db
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_PASSWORD: wordpress
    volumes:
      - wordpress/:/var/www/html/

volumes:
    wordpress:

However after bringing everything up successfully I cannot find where the named volume exists on my Mac.

MacBookAir:wordpress carlwainwright$ docker volume inspect wordpress_wordpress
[
    {
        "Name": "wordpress_wordpress",
        "Driver": "local",
        "Mountpoint": "/var/lib/docker/volumes/wordpress_wordpress/_data",
        "Labels": null,
        "Scope": "local"
    }
]
MacBookAir:wordpress carlwainwright$ ls -l /var/lib/docker/volumes/wordpress_wordpress/_data/
ls: /var/lib/docker/volumes/wordpress_wordpress/_data/: No such file or directory

Any ideas?


回答1:


Please keep in mind, Docker for Mac runs a docker engine in a Linux VM, not your Mac OS, so you can't find the volume's mount point in your Mac OS file system. The volume files should existing in that Linux VM's file system.

However, you can login Docker for Mac's VM via screen:

$ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty  
#user: root
#password: xxxxxx

Then you can view the docker's volumes:

$ ls -ltrh /var/lib/docker/volumes
total 148
drwxr-xr-x    3 root     root          4096 May 16 13:20 04576d248c19b1210d47e94c8211493428cd3c3aa71dfe3fa0f4214589a6f875
drwxr-xr-x    3 root     root          4096 May 16 13:20 31af0f01492d8f7b832dad75e731b754302e84fbecfa7c654d7de10465bec204
etc.


来源:https://stackoverflow.com/questions/39763115/docker-named-volume-location-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!