Management after installing docker

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

Insert picture description here

Download mirror

docker pull nginx

Insert picture description here

View download mirror information

docker images

Insert picture description here

Obtain mirror information

docker inspect 镜像id

Insert picture description here

add tag

docker tag nginx:latest nginx:www

Insert picture description here

Delete mirror

docker rmi nginx:www

Insert picture description here

Export (backup)

cd /opt
docker save  -o nginx nginx:latest
#导出镜像,命名为nginx

Insert picture description here

Import

方法一:docker load < nginx
方法二:docker --input nginx

Insert picture description here

Second, the container

Create a container

docker create -it nginx:latest /bin/bash

Insert picture description here

Start the container

docker start 容器id

Insert picture description here

View container

docker ps       #查看运行中的容器
docker ps -a    #查看所以容器

Insert picture description here

Start execution command

#-i:表示标准输入
#-t:指定一个伪终端(环境)
#-d:开启守护进程(后台运行)

docker run -it nginx:latest /bin/bash
docker run -itd nginx:latest /bin/bash	

#前面的下载镜像、创建容器、启动容器。可以用这步代替,非常方便。

Insert picture description here

Terminate operation

docker stop 70c3b78dd8c6

Insert picture description here

Container entry

docker exec -it 容器id /bin/bash

#进入正在运行的容器
docker attach 容器id 

Insert picture description here
Insert picture description here

Container export

docker export 镜像id > 目录/文件名

Insert picture description here

Container import

cat 目录/文件名 | docker import - 镜像名:标签
#会生成镜像,而不会创建容器

Insert picture description here

Delete container

docker rm 容器id

Insert picture description here

batch deletion

docker ps -a | awk '{print " docker rm " $1}' | bash

Insert picture description here

Exposed port

#-p:暴露指定端口
#-P:暴露随机端口

Insert picture description here
Insert picture description here

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地址

Insert picture description here
Insert picture description here
Insert picture description here

Data volume and data volume container

两者区别:
数据卷是宿主机和容器之间的共享
数据卷容器是容器和容器之间的共享

例:数据卷
docker run -v /var/www:/data1 --name web1 -it centos /bin/bash

Insert picture description here

例:数据卷容器
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

Insert picture description here

Three, private warehouse

Create warehouse

docker pull registry

Insert picture description here

vim /etc/docker/daemon.json

{
    
    
  "insecure-registries":["192.168.109.55:5000"],
  "registry-mirrors": ["https://fprozkd6.mirror.aliyuncs.com"]
}

Insert picture description here

systemctl restart docker.service 
docker create -it registry /bin/bash
docker ps -a
docker start 容器id

Insert picture description here
Insert picture description here

Mount the container

# #宿主机的/data/registry自动创建挂载容器中的/tmp/registry
docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry    

Insert picture description here

#更改标记为192.168.126.70:5000/nginx
docker tag nginx:latest 192.168.109.55:5000/nginx

Insert picture description here

Upload

# 上传
docker push 192.168.109.55:5000/nginx

Insert picture description here

Get a list of private repositories

# 获取私有仓库列表
curl -XGET http://192.168.109.55:5000/v2/_catalog

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51616026/article/details/115115547