1. 挂载本地的目录到容器里: docker run -itd -v /data/:/data1 centos bash // -v 用来指定挂载目录, :前面的/data为本地目录,:后面的/data1 为容器里的目录: docker:/root# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos_6.5_all scan f01c69d919d1 5 hours ago 975.4 MB centos_6.5 zjzc a05f15a89c8d 6 hours ago 924 MB centos-6-x86-template zjzc 50fca37b01a1 6 hours ago 574.3 MB centos_6.5_net scan 9e2de3fc0748 24 hours ago 398.6 MB centos_with_net czcb 92b2e7f857ae 26 hours ago 269.5 MB ubuntu latest c917d6497f55 2 days ago 187.9 MB januswel/centos latest 088820de4929 13 days ago 198.3 MB linux123 xxx123 088820de4929 13 days ago 198.3 MB linux123 jj 088820de4929 13 days ago 198.3 MB linux123 latest 088820de4929 13 days ago 198.3 MB 172.17.42.1:5000/zjzc-test01 latest bb3d629a7cbc 13 days ago 196.6 MB centos latest bb3d629a7cbc 13 days ago 196.6 MB 192.168.32.150:5000/zjzc-test02 latest bb3d629a7cbc 13 days ago 196.6 MB registry latest 07d93e41c370 7 weeks ago 422.8 MB blalor/centos latest f01c1b138488 21 months ago 322.4 MB docker:/root# docker run -itd -v /data/:/data1 centos_6.5_all:scan bash c6643476b61ba633a18a1c5e414f16f8120b0dd25b6efd2a164e1dac8a349720 docker:/root# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c6643476b61b centos_6.5_all:scan "bash" 27 seconds ago Up 26 seconds jovial_mclean 402620f666c1 registry "docker-registry" 55 minutes ago Up 39 minutes 0.0.0.0:5000->5000/tcp gloomy_brown docker:/root# docker exec -it c6643476b61b bash bash-4.1# df -h Filesystem Size Used Avail Use% Mounted on rootfs 9.8G 827M 8.5G 9% / /dev/mapper/docker-253:0-131624-c6643476b61ba633a18a1c5e414f16f8120b0dd25b6efd2a164e1dac8a349720 9.8G 827M 8.5G 9% / tmpfs 939M 0 939M 0% /dev shm 64M 0 64M 0% /dev/shm /dev/mapper/vg00-lv_root 97G 9.0G 83G 10% /data1 挂载数据卷: 新的容器使用旧的容器的数据卷: docker:/root# docker run -itd --name zjzc_z1 --volumes-from zjzc_awp centos bash bd6db4127a9e885990753f9d3036e3d060268dd8c4a03d03844e8d5fa53b1a6b docker:/root# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bd6db4127a9e centos "bash" 2 seconds ago Up 2 seconds zjzc_z1 docker:/root# docker exec -it bd6db4127a9e bash [root@bd6db4127a9e /]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/docker-253:0-131624-bd6db4127a9e885990753f9d3036e3d060268dd8c4a03d03844e8d5fa53b1a6b 10190136 235372 9430476 3% / tmpfs 961124 0 961124 0% /dev shm 65536 0 65536 0% /dev/shm /dev/mapper/vg00-lv_root 100758960 9388664 86246536 10% /data2