以后台形式启动一个ubuntu容器,挂载本地$PWD目录,默认是读写权限都有,如果需要只读,加只读参数 /asdf:ro
$ docker run --name ubuntu02 -d -ti -v "$PWD":/asdf ubuntu:14.04 /bin/bash
15a4a59a52f98f76d54bb88c37d9a0577b423e97aa146b6a715a1c8d1bb06264
查看容器:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15a4a59a52f9 ubuntu:14.04 "/bin/bash" 29 seconds ago Up 27 seconds ubuntu02
查看挂载情况:
$ docker inspect -f {{.Mounts}} 15a4a59a52f9
[{bind /home/docker /asdf true }]
利用docker-enter 进入容器查看/asdf 目录是否为宿主机的/home/docker/mysql 目录
$ docker-enter 15a4a59a52f9 /bin/bash
root@15a4a59a52f9:/# ls
asdf bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@15a4a59a52f9:/# pwd
/
root@15a4a59a52f9:/# cd /asdf/
root@15a4a59a52f9:/asdf# ls
mysql
root@15a4a59a52f9:/asdf#