安装 [root@localhost soft]# yum install -y docker
查看版本 [root@localhost soft]# docker version
启动 [root@localhost soft]# systemctl start docker
下载镜像 [root@localhost soft]# docker run centos:7 sleep 1000
查看运行的docker [root@localhost ~]# docker ps
查看docker镜像 [root@localhost ~]# docker images
[root@localhost ~]# docker run -t -i centos:7 ls
[root@localhost ~]# docker run -t -i centos:7 bash
列出所有容器 [root@localhost ~]# docker ps -a
查看容器的信息 [root@localhost ~]# docker inspect {CONTAINER ID}
以后台模式运行 [root@localhost ~]# docker run -d centos:7 sleep 1000
停止正在运行的容器 [root@localhost ~]# docker stop 14c70b5194d4
启动容器 [root@localhost ~]# docker start {CONTAINER ID} //run 新起一个 start启动已经存在的
删除一个容器 [root@localhost ~]# docker rm -f 14c70b5194d4
启动时给容器起个名字 [root@localhost ~]# docker run -d --name hello centos:7 sleep 10
启动tomcat镜像 [root@localhost ~]# docker run -d -p 9000:8080 tomcat:7
查看启动日志 [root@localhost ~]# docker logs 21a050a1cddd
使用docker commit创建镜像 [root@localhost ~]# docker commit 9e39a770a3a8 showe/git:1.0
启动刚刚创建的镜像 [root@localhost ~]# docker run -it showe/git:1.0 bash
使用dockerfile创建镜像
[root@localhost dockerfile.d]# vi Dockerfile
FROM centos:7
RUN yum update -y
RUN yum install -y git curl //这种方式创建的镜像,在使用history查看是会发现创建了两层 可以改为链式
//RUN yum update -y && yum install -y git curl 层数越少,镜像的越小
[root@localhost dockerfile.d]# docker build -t showe/git:2.0 .
[root@localhost dockerfile.d]# docker history showe/git:2.0
Dockerfile
CMD命令 1. CMD命令指定容器启动时执行什么命令 2.如果在Dockerfile中不指定CMD命令,Dockerfile将使用基础镜像提供的默认命令 3.CMD命令在创建镜像是不执行,只有在容器启动时才执行
[root@localhost dockerfile.d]# docker login
[root@localhost dockerfile.d]# docker push
单机容器间通讯
1. link
2.Docker Compose
跨机通讯使用swarm k8s
docker的网络
bridge模型
# docker network
# docker run -d --rm --name c1 busybox sleep 500
# docker network inspect bridge
# docker run -d --rm --name c2 busybox sleep 500
# docker exec -ti c2 ifconfig
#docker exec -ti c1 ping {c2 ip}
#docker network create --driver bridge mynet //创建网络
#docker network list
#docker network inspect mynet
#docker run --rm -d --name c3 --net mynet busybox sleep 500 //指定使用mynet网络
#docker network connect mynet c1 //将容器连接到指定的网络上
host模型
#docker run --rm -d --name host1 --net host busybox sleep 100
使用docker-compose管理网络