容器卷

This commit is contained in:
法然
2022-10-08 23:19:45 +08:00
parent e359df4680
commit a7142963f4
23 changed files with 719 additions and 3 deletions

View File

@@ -247,7 +247,7 @@ exit
### docker rm删除容器
*
* 删除容器
```
docker rm container_id 删除指定的容器,不能删除正在运行的容器。
-f 可以删除正在运行的容器
@@ -565,7 +565,7 @@ docker attach containerid
### docker cp从容器内拷贝到主机上
* docker cp id
* id
* 进入容器,
* 创建文件
* 拷贝文件

View File

@@ -115,6 +115,82 @@ docker run -d -P --name nginx02 -v juming-nginx:/etc/nginx:rw nginx
## 3 DockerFile构建docker镜像文件
Dockerfile 用来构建docker镜像的构建文件就是命令脚本。
* 通过这个脚本可以生成镜像,镜像就是一层一层的。脚本是一个个的命令,每个命令是一层。
```shell
# 创建一个dockerfile文件名字尽量为dockerfile
# 文件中的恩荣,指令大写,参数
➜ test_volume cat dockerfile1
FROM centos
VOLUME ["volume01","volume02"]
CMD echo "--end--"
CMD /bin/bashs
# 这里的每个命令,都是镜像中的一层。
```
![](image/2022-10-08-21-55-08.png)
* 运行并查看我们自己创建的镜像。可以看到挂载的卷。这是一个匿名挂载,只包含容器内的文件路径。
![](image/2022-10-08-22-01-46.png)
![](image/2022-10-08-21-57-57.png)
![](image/2022-10-08-22-02-04.png)
* 使用docker inspect能够查看卷挂载的路径。
![](image/2022-10-08-22-00-28.png)
* 最后测试一下文件是否同步。
![](image/2022-10-08-22-17-15.png)
* mac下无法访问/var/lib/docker目录。解决方案
```
# 拉取镜像并运行进入VM然后就可以找到/var/lib/docker
docker run -it --rm --privileged --pid=host justincormack/nsenter1
/ # hostname
docker-desktop
/ # uname -a
Linux docker-desktop 5.10.47-linuxkit #1 SMP Sat Jul 3 21:51:47 UTC 2021 x86_64 Linux
/ # cd /var/lib/docker/containers/
/var/lib/docker/containers # ls
469a5c56d4dcfa1f10228e4a10da5fdef2576d046bf83b99066ded54aeb93f90
a2158f98ccbfe057f8bf4d9c0f3a34b8408ed1bdb22ae72ea90cb781df6af166
b0bca090076ae5e683469b95ef7279b43ae941fb7ad7732ce233057a175225d8
d211d5e9bd3e094b37699e9163825c8941e6eff03c036fd3ffc774364db99493
d4df5c6e11115695fbc4d61cd018ab8a59006a6b9373ba837bf7003df8fd14bb
/var/lib/docker/containers # ls ../volumes/
0bc95ec18e21b6fe455581b48fc8784159e5b3de52037ae0b01dc30a978b3ed7
45f7d5b3f9a819b8035b088d4bfea306f1a54c3c5257cdc0f733d24691be8dcd
54c34557ba83af6f142a0916c7eddc36acdb1652eb9b5123ff5c40f6e1e7e4e8
79d875e4bb162d15417d9a1768b0042c2d08203450dcb904e69f01816927a07a
b2d98f27082a7864f83aaf667858f3fad39a02819cd4e00e61279a7d30589159
backingFsBlockDev
c4a9d80b6636e6dede8c637210dad9abf1b476a63f38848c767802de735a51dc
db8dcda5d651ec433d83cfeee5dd6d4be198a13d9fe5c103410060addab014ac
metadata.db
nginxconfig
```
## 4
## 4 数据卷容器
### 共享原理
![](image/2022-10-08-22-27-25.png)
### 数据共享
* 通过vulumes-from 参数实现数据共享
![](image/2022-10-08-23-06-28.png)
```shell
docker run -it --name docker01 --volumes-from a04eb38b1a38 yinkanglong/hello
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 873 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB