docker安装/镜像/容器操作
-----------------安装依赖包------------------------------------
yum install -y yum-utils device-mapper-persistent-data lvm2
-------------设置阿里云镜像----------------------
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
------------安装docker-CE-------------------
yum install -y docker-ce
systemctl stop firewalld.service
setenforce 0
systemctl start docker.service
systemctl enable docker.service
------------------镜像加速--------------------------
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://w1nluipe.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
--------------------增删改查------------------------
docker version
docker search nginx //查找nginx
docker pull nginx //下载nginx
docker images //查看镜像(IMAGE ID是镜像唯一标识)
docker inspect f6d0b4767a6c //查看镜像详细信息
docker tag nginx:latest nginx:web //修改镜像标签tag
docker rmi nginx:web //删除某一镜像
------------------------镜像备份还原--------------------------------
迁移:
docker save -o nginx nginx:latest //导出nginx:web镜像为nginx文件
还原:
scp /opt/nginx root@192.168.2.130:/opt/
导入
docker load < nginx
-----------------上传共有仓库-----------------
docker login //登录docke仓库账号
docker push nginx:web //上传镜像
----------------------------容器操作---------------
docker ps -a //查看容器(CONTAINER ID为唯一标识)
docker create -it nginx:latest /bin/bash //创建容器
docker start ef9ac42a0548 //启动容器
----------------------下面命令---------------
docker run paigeeworld/centos7 /usr/bin/bash -c ls //此命令可以一气呵成,从查找到下载到创建容器到start容器到进入容器到ls
docker exec -it cd07207750e4 /bin/bash //进入容器
exit //推出容器
docker stop cd07207750e4 //禁用容器,停止容器
docker rm cd07207750e4 //删除容器
------------------------持续后台运行容器------------------------
docker run -d
----------------容器导出导入-------------
docker export ef9ac42a0548 > nginx_c //导出容器到nginx_C
scp /opt/nginx_c root@192.168.2.130:/opt/
还原(还原成了镜像而不是容器)
cat nginx_c | docker import - nginx:web
docker create -it nginx:web /bin/bash //加载到容器
从而就有了容器
-----------容器批量删除---------
docker ps -a | awk '{print "docker rm "$1}' //列出容器id
docker ps -a | awk '{print "docker rm "$1}' | bash //删除无效的容器(up状态不会删除的)