容器指定路径挂载数据卷
程序员文章站
2022-04-25 15:16:34
...
书写Dockerfile文件
cd /tmp/docker
vim Dockerfile
FROM rhel7
ADD html.tar /usr/share
VOLUME ["usr/share/nginx/html"]
mkdir nginx
cd nginx/
mkdir html
mv index.html ./nginx/html/ # 写一个首页文件
tar cf nginx/ html.tar # 打包,以便解压生成目录,得到挂载路径
docker build -t rhel7:v4 .
[root@foundation11 test]# docker create --name vol rhel7:v4 bash # 创建数据卷
7bc689c9ffd77a1b0c5dfe1f360389150bfe6987b0c17440f26ae462e6a8ee0a
[root@foundation11 test]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@foundation11 test]# docker run -d --name vm1 --volumes-from vol nginx
eca23d83c5256f4018d508d89e5c1d1002d1b041abb3e7364e2397169cc0a836
docker inspect vm1
[aaa@qq.com test]# curl 172.17.0.2
<h1>www.westos.org<h1>
<h1>www.westos.org<h1>
<h1>www.westos.org<h1>
<h1>www.westos.org<h1>
<h1>www.westos.org<h1>
gyugdhiuewjd\n yustdyewujfd