Docker introduces common commands to organize

What is docker

An open source application container engine, based on the Go language and open source following the Apache2.0 protocol.

Docker architecture

Docker includes three basic concepts:

  • Image: Docker image is equivalent to a root file system.

  • Container: The relationship between the image and the container is like the class and instance in java object-oriented programming. The image is a static definition, and the container is the entity of the image at runtime. Containers can be created, started, stopped, deleted, suspended, etc.

  • Repository: The repository can be regarded as a code control center for storing images.

CentOs Docker installation

Use the official installation script to automatically install the
installation command as follows:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

You can also use the domestic daocloud one-click installation command:

curl -sSL https://get.daocloud.io/docker | sh

Docker image acceleration

Manually configure the Docker accelerator (vim /etc/docker/daemon.json), add the following configuration

{ "Registry-mirrors": ["accelerated address"]

}

Sometimes it is difficult to pull images from DockerHub in China. At this time, you can configure the image accelerator. Docker official and many domestic cloud service providers provide domestic accelerator services, such as:

NetEase: https://hub-mirror.c.163.com/ Aliyun
: https://<your ID>.mirror.aliyuncs.com Qiniu
Cloud Accelerator: https://reg-mirror.qiniu.com
After configuring a certain accelerator address, if you find that the image cannot be pulled, please switch to another accelerator address. All major domestic cloud service providers provide Docker image acceleration services. It is recommended to select the corresponding image acceleration service according to the cloud platform running Docker.

Alibaba Cloud mirror acquisition address: https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors, after logging in, select the mirror accelerator in the left menu and you will see your exclusive address:
Insert picture description here

Docker commonly used commands

1 Use keywords to search for mirrors

# 使用关键字搜索镜像
docker search  xxx

2 View local images/containers

# 镜像
docker images
# 容器
docker ps
docker ps-a

3 pull

# 拉取版本镜像到本地 不指定版本默认最新
docker pull name:版本号`  

4 Run the container

# -d 后台运行
# -p 8080:80 宿主机的8080端口映射到docker内部的80端口
# -P :是容器内部端口随机映射到主机的高端口
# --name docker-nginx 启动后的容器名称为docker-nginx
docker run -d -p 8080:80 --name docker-nginx nginx

5 Shut down and restart

docker  kill / stop
docker start / restart

6 docker cp

# 将nginx容器内部的/etc/nginx文件夹复制到本机当前运行目录
docker cp nginx:/etc/nginx ./
 
# 将nginx容器内部的/etc/nginx/nginx.conf文件复制到本机当前运行目录
docker cp nginx:/etc/nginx/nginx.conf ./
 
# 将本机当前运行目录下的的test文件复制到nginx容器内部的/etc/nginx/目录下
docker cp ./test nginx:/etc/nginx/

7 Enter the container to modify the file

 sudo docker exec -it 容器Id  /bin/bash 

Docker container connection

https://blog.csdn.net/jacksonary/article/details/78961612

Guess you like

Origin blog.csdn.net/qq_38095257/article/details/110822861