docker 加速
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
二。常见的容器操作方式:
创建一个容器 -i交互式 -t分配伪终端 -d运行到后台
docker container run -itd nginx
docker ps -a
容器资源限制 -m最大内存量 -memory-swap允许交换到磁盘的内存量 -oom-kill-disable禁用OOM Killer -cpus可以使用的CPU数量
docker run -d --name web01 --memory="10m" --memory-swap="20m" --oom-kill-disable nginx
docker stats --no-stream web01
CPU限额 允许使用一个半的CPU
docker run -d --name nginx02 --cpus="1.5" nginx
进入容器中:
docker exec -it web04 bash
退出
exit
提交容器为新的镜像:
docker commit web04 newweb04
logs查看日志
docker logs web04
停止/启动一个或多个容器
docker start/stop web-4
删除一个或多个容器
docker rm web04
三。宿主机挂载数据到容器
volumes 管理宿主机文件系统
管理卷
# 创建卷,查看卷,查看卷详细信息。所有的卷默认数据保存在 /var/lib/docker/volumes/nginx-vol/_data 中
docker volume create nginx-vol
docker volume ls
docker volume inspect nginx-vol
# 为卷创建一个容器,mount指定数据卷,dst指定数据卷挂在容器的目录
docker run -itd --name=nginx-test -p 88:80 --mount src=nginx-vol,dst=/usr/share/nginx/html nginx
docker exec -it nginx-test bash
# 此时若在容器中创建一个文件,那么在数据卷中也会保存一份该文件
# 若在 数据卷中创建一个文件 a.html ,在容器中通过 localhost:88/a.html 也可以访问,
vi a.html
<h1>hello 123</h1>
# 删除容器后,数据卷中的 1.html 依旧还在
docker rm nginx-test
bind mounts 将宿主机的文件挂载到容器中
docker run -d --name nginx04 -p 88:80 --mount type=bind,src=/mnt/,dst=/usr/share/nginx/html nginx