容器的操作
docker inspect f6d0b4767a6c #获取镜像
docker ps #查看容器
docker start 24482430b294 #启动容器
docker ps -a #查看状态为up
docker run -d centos:7 /bin/bash -c ls /
#这条命令,每运行一个就会多一个镜像,因为run可以快捷创建镜像启动镜像服务
docker run -d centos:7 /bin/bash -c "while true;do echo hello;done"
docker exec -it de052bd8c791 /bin/bash
exit 退出容器
docker run -itd nginx:latest /bin/bash #启动容器
cat /opt/nginx.bak | docker import - nginx #导出指定的镜像,到指定的目录中
docker export e1da8b9e3b9d > /opt/nginx.bak:web #从指定的目录中导入指定的镜像
docker rm 镜像号 #删除容器
docker ps -a | awk '{print"docker rm "$1}' | bash #批量删除容器
私有仓库建立
[root@localhost ~] # docker pull registry
[root@localhost ~] # vim /etc/docker/daemon.json
"insecure-registries":["192.168.162.20:5000"],
[root@localhost ~] # systemctl restart docker
[root@localhost ~] # systemctl status docker
[root@localhost ~] # docker create -it registry /bin/bash
docker start eb4d6dbd61fe
docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry
[root@localhost ~] # docker push 192.168.162.20:5000/nginx
[root@localhost ~] # curl -XGET http://192.168.162.20:5000/v2/_catalog
[root@localhost ~] # docker ps -a
[root@localhost ~] # docker rmi eb4d6dbd61fe
[root@localhost ~] # docker ps -a
[root@localhost ~] # docker images
[root@localhost ~] # docker rmi nginx:web
[root@localhost ~] # docker images
[root@localhost ~] # docker pull 192.168.162.20:5000/nginx
[root@localhost ~] # docker images
Docker数据卷
[root@localhost ~] # docker pull centos:7
[root@localhost ~] # docker run -v /share:/data1 --name web1 -it centos:7 /bin/bash
[root@localhost ~] # docker run -v /share:/data1 --name web1 -it centos:7 /bin/bash
[root@09ae29e4ae43 data1]# touch kk
[root@09ae29e4ae43 data1]# exit
[root@localhost ~] # cd /share/
[root@localhost /share] # ls
kk
数据卷容器
数据卷容器
[root@localhost /share] # docker run --name web100 -v /data1 -v /data2 -it centos:7 /bin/bash
新容器挂载数据卷容器web100
[root@localhost ~] # docker run -it --volumes-from web100 --name web200 centos:7 /bin/bash
端口映射
[root@localhost ~] # docker run -d -P nginx
[root@bogon ~] # docker run -it -d -p 49280:80 nginx
[root@localhost ~] # docker ps -a
容器互联(使用centos镜像)
docker run -itb -P --name web11 centos:7 /bin/bash #创建并运行容器取名web11,端口号自动映射
docker run -itb -P --name web22 --link web11:web11 centos:7 /bin/bash #创建并运行容器取名web22,链接到web11和其通信
[root@bogon ~] # docker exec -it 8864d64d7215 bash
进入web22容器pingweb11