安装启动docker
yum install docker
service docker start
为了避免端口通信的问题,我们先关闭两台机器的防火墙以及重启一下docker:
systemctl stop firewalld
systemctl restart docker
Docker连接登陆docker hub 需先安装启动daemon
systemctl daemon-reload
systemctl restart docker.service
Docker 清理
curl -s https://raw.githubusercontent.com/ZZROTDesign/docker-clean/v2.0.4/docker-clean |
sudo tee /usr/local/bin/docker-clean > /dev/null &&
sudo chmod +x /usr/local/bin/docker-clean
docker-clean
将 ec2-user 添加到 docker 组,以便您能够执行 Docker 命令,而无需使用 sudo
sudo usermod -a -G docker ec2-user
docker查看桥接端口
docker network inspect bridge
拉取镜像:
docker pull wangfantestweb/hellodockertest:developserver
上传镜像:
先修改Tag, docker tag docker.io/wangfantestweb/hellodockertest:developserver qq1336051741/webclientpublic:developserver
在上传镜像,docker push qq1336051741/webclientpublic:developserver
直接运行容器:
开发态:
①
docker run -i -t -p 8001:8001 -p 8002:8002 -p 23001:23001 --name developserver --privileged=true wangfantestweb/hellodockertest:developserver (/bin/bash)
②(挂载数据卷)
docker run -i -t -v /home/XING/DevelopServer/Server:/home/KfWeb_product/DevelopServer/Server -v /home/XING/RunServer/Server:/home/KfWeb_product/RunServer/Server -p 8001:8001 -p 8002:8002 -p 23001:23001 --name developserver --privileged=true wangfantestweb/hellodockertest:developserver
运行态:
①
docker run -i -t -p 8003:8003 -p 8004:8004 -p 23001:23001 --name runserver --privileged=true wangfantestweb/hellodockertest:runserver (/bin/bash)
②挂载数据卷
docker run -i -t -v /home/XING/DevelopServer/Server:/home/KfWeb_product/DevelopServer/Server -v /home/XING/RunServer/Server:/home/KfWeb_product/RunServer/Server -p 8003:8003 -p 8004:8004 -p 23001:23001 --name runserver --privileged=true wangfantestweb/hellodockertest:runserver
用户服务:
docker run -i -t -p 8000:8000 -p 23001:23001 --name usrserver --privileged=true wangfantestweb/hellodockertest:usrserver (/bin/bash)
docker基本指令:
查看本地镜像:docker images
查看运行中的容器: docker ps
查看所有容器: docker ps -a
退出容器终端并保持容器继续运行: CTRL+P+Q
关闭一个容器: docker stop/kill [容器名]
删除一个容器: docker rm [容器名]
删除一个镜像: docker rmi [镜像名]
启动所有容器的命令: docker start $(docker ps -a | awk ‘{print $I}’ | tail -n +2)
关闭所有容器的命令:docker stop $(docker ps -a | awk ‘{print $I}’ | tail -n +2)
删除所有容器的命令: docker rm $(docker ps -a | awk ‘{print $I}’ | tail -n +2)
关闭所有镜像的命令:docker rmi $(docker ps -a | awk ‘{print $I}’ | tail -n +2)