Docker container installation and basic command operations

Abstract: Docker is an open source application container engine that can easily create a lightweight, portable, self-sufficient container for any application. Containers that developers compile and test locally can be deployed in batches in production environments, including VMs (virtual machines), baremetal, OpenStack clusters and other basic application platforms. To simply understand, Docker is similar to a container. All kinds of goods are managed through the standardization of containers, and there is no impact between containers. In other words, the Docker platform is a software containerization platform, which means that we can build the application ourselves, package its dependencies together into a container, and then the container can be easily shipped to other machines for running. It is also very easy to load, copy, and remove, making it very suitable for software elastic architecture.

1. Install docker service and configure image accelerator
1. Install some necessary system tools
[root@node ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
2. Add software source information
[root@node ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3. Update the source and install Docker-ce
[root@node ~]# yum makecache fast
[root@node ~]# yum list docker-ce.x86_64 --showduplicates | sort -r		# 查找docker-ce的版本
[root@node ~]# yum install docker-ce 3:24.0.5-1.el7 	# 安装指定版本docker
4. Installation verification
[root@node ~]# docker version
Client: Docker Engine - Community
 Version:           24.0.5
 API version:       1.43
 Go version:        go1.20.6
 Git commit:        ced0996
 Built:             Fri Jul 21 20:39:02 2023
 OS/Arch:           linux/amd64
 Context:           default
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
5.docker image acceleration

You can view the configuration of the image accelerator in Alibaba Cloud's container image service.

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://ggsypcee.mirror.aliyuncs.com"]
}
EOF
	
[root@node ~]# systemctl daemon-reload		 # 重新加载docker配置
[root@node ~]# systemctl restart docker	   # 重启docker服务
[root@node ~]# systemctl enable docker		 # 设为开机自启
2. Download the system image (Ubuntu, centos)
[root@node ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

[root@node ~]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete 
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
3. Create two containers based on the downloaded image
[root@node ~]# docker run --name zhujialiang -it centos 
[root@node ~]# docker run --name zjl -it ubuntu
root@7453cd6fcb8e:/# 
4. Start, stop and restart operations of containers
1. Start the container and restart it
[root@node ~]# docker start zjl
[root@node ~]# docker restart zjl
2. View the container
[root@node ~]# docker ps 
[root@node ~]# docker container ls 
3. Close the container
[root@node ~]# docker stop zjl
[root@node ~]# docker kill zjl
4. View container details
[root@node ~]# docker inspect zjl | grep -i Address
5. How to view running containers and all containers?
# 查看正在运行的
[root@node ~]# docker ps  
[root@node ~]# docker container ls
# 查看所有容器
[root@node ~]# docker ps -a
[root@node ~]# docker container ls -a
6. How to exit the container: Are the two methods implemented separately?
[root@node ~]# docker run --name zjl -it centos /bin/bash
[root@3c4c6960e31c /]# exit
[root@node ~]# docker stop zjl1
7. How to connect to the running container?
[root@node ~]# docker exec -it zjl /bin/bash
8. View the internal information of the container or image?
[root@node ~]# docker inspect zjl
9. How to view all images?
[root@node ~]# docker images
[root@node ~]# docker image ls

Supongo que te gusta

Origin blog.csdn.net/m0_50816276/article/details/132378998
Recomendado
Clasificación