table of Contents
Let's take a closer look at today's content from the three cores of docker
One, mirror
Find the specified mirror
docker search nginx
Download mirror
docker pull nginx
View download mirror information
docker images
Obtain mirror information
docker inspect 镜像id
add tag
docker tag nginx:latest nginx:www
Delete mirror
docker rmi nginx:www
Export (backup)
cd /opt
docker save -o nginx nginx:latest
#导出镜像,命名为nginx
Import
方法一:docker load < nginx
方法二:docker --input nginx
Second, the container
Create a container
docker create -it nginx:latest /bin/bash
Start the container
docker start 容器id
View container
docker ps #查看运行中的容器
docker ps -a #查看所以容器
Start execution command
#-i:表示标准输入
#-t:指定一个伪终端(环境)
#-d:开启守护进程(后台运行)
docker run -it nginx:latest /bin/bash
docker run -itd nginx:latest /bin/bash
#前面的下载镜像、创建容器、启动容器。可以用这步代替,非常方便。
Terminate operation
docker stop 70c3b78dd8c6
Container entry
docker exec -it 容器id /bin/bash
#进入正在运行的容器
docker attach 容器id
Container export
docker export 镜像id > 目录/文件名
Container import
cat 目录/文件名 | docker import - 镜像名:标签
#会生成镜像,而不会创建容器
Delete container
docker rm 容器id
batch deletion
docker ps -a | awk '{print " docker rm " $1}' | bash
Exposed port
#-p:暴露指定端口
#-P:暴露随机端口
Link container
--link
例:
docker pull centos:7
docker run -itd -P --name web1 centos:7 /bin/bash
docker run -itd -P --name web2 --link web1 centos:7 /bin/bash
docker ps
docker attach web1镜像id
yum -y install net-tools
#获取IP地址
ifconfig
docker ps
docker attach web2镜像id
ping web1IP地址
Data volume and data volume container
两者区别:
数据卷是宿主机和容器之间的共享
数据卷容器是容器和容器之间的共享
例:数据卷
docker run -v /var/www:/data1 --name web1 -it centos /bin/bash
例:数据卷容器
docker run --name web100 -v /data1 -v /data2 -it centos:7 /bin/bash
docker run -it --volumes-from web100 --name db1 centos:7 /bin/bash
Three, private warehouse
Create warehouse
docker pull registry
vim /etc/docker/daemon.json
{
"insecure-registries":["192.168.109.55:5000"],
"registry-mirrors": ["https://fprozkd6.mirror.aliyuncs.com"]
}
systemctl restart docker.service
docker create -it registry /bin/bash
docker ps -a
docker start 容器id
Mount the container
# #宿主机的/data/registry自动创建挂载容器中的/tmp/registry
docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry
#更改标记为192.168.126.70:5000/nginx
docker tag nginx:latest 192.168.109.55:5000/nginx
Upload
# 上传
docker push 192.168.109.55:5000/nginx
Get a list of private repositories
# 获取私有仓库列表
curl -XGET http://192.168.109.55:5000/v2/_catalog