运维-docker-容器数据持久化保存&&同步时间

87 阅读1分钟

举一个简单例子

步骤一:主机服务器创建文件

mkdir /web
echo "web" >> /web/index.html

步骤二:启动容器时候对目录进行挂载

docker run -it -p 8080:80/tcp -v /web:/var/www/html --name c1 centos:latest /bin/bash

步骤三:容器安装启动httpd服务器,然后在主机访问,在主机通过修改挂载目录的index文件内容试验

容器内
yum install httpd
httpd -k start

docker主机上
curl http://localhost:8080

步骤四:同步容器与docker host时间

启动时候同步时间
docker run -it -v /etc/localtime:/etc/localtime centos:latest /bin/bash

命令查看时间
date