moneyslow.com

docker--启动一个容器利用docker inspect -f {{.Mounts}} 查看容器内目录和对应宿主机目录对应关系

建立容器,配置一个默认的“数据容器”,卷名称为cookbook

# docker run -it -v /cookbook ubuntu:14.04 /bin/bash

Unable to find image 'ubuntu:14.04' locally
14.04: Pulling from library/ubuntu
cf0a75889057: Pull complete 
c8de9902faf0: Pull complete 
a3c0f7711c5e: Pull complete 
e6391432e12c: Pull complete 
624ce029a17f: Pull complete 
Digest: sha256:b2a55128abd84a99436157c2fc759cf0a525c273722460e6f8f9630747dfe7e8

Status: Downloaded newer image for ubuntu:14.04

在容器内建立一个文件:

root@ed38309b8e26:/# cd cookbook/
root@ed38309b8e26:/cookbook# touch foobar

root@ed38309b8e26:/cookbook# exit

查看容器id

# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                      PORTS               NAMES
ed38309b8e26        ubuntu:14.04        "/bin/bash"         About a minute ago   Exited (0) 24 seconds ago                       hopeful_heisenberg

查看容器内/cookbook和宿主机目录的对应关系:

# docker inspect -f {{.Mounts}} ed38309b8e26
[{volume 067bbdd059ecb83fe2fd7611dc4ce46233b94ff887969754dde443231996e26d /var/lib/docker/volumes/067bbdd059ecb83fe2fd7611dc4ce46233b94ff887969754dde443231996e26d/_data /cookbook local  true }]

验证:

# ls /var/lib/docker/volumes/067bbdd059ecb83fe2fd7611dc4ce46233b94ff887969754dde443231996e26d/_data
foobar

两种方式改写这个volumn

1、进入容器操作: docker-enter ed38309b8e26 /bin/bash

2、宿主机操作: cd /var/lib/docker/volumes/067bbdd059ecb83fe2fd7611dc4ce46233b94ff887969754dde443231996e26d/_data

Exit mobile version