一、简介
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows操作系统的机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
二、docker安装
以下三种方式都可以进行安装
(1)官方安装脚本安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
(2)国内daocloud命令安装
curl -sSL https://get.daocloud.io/docker | sh
(3)手动安装
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
三、安装 Docker Engine-Community
1、安装所需的软件包
安装device-mapper-persistent-data 和 lvm2
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
2、设置仓库
海外
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
国内
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3、安装
sudo yum install docker-ce docker-ce-cli containerd.io
四、启动/关闭docker
启动
sudo systemctl start docker
重启
systemctl restart docker
关闭
systemctl stop docker
五、验证
[root@root ~]# docker version
Client: Docker Engine - Community
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:49:57 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.14
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 87a90dc
Built: Thu Mar 24 01:48:24 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.11
GitCommit: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@root ~]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
[root@root ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
28d861603b7c hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago reverent_bhabha
六、配置镜像加速
登录阿里云-工作台-容器镜像服务-镜像工具-镜像加速器获取自己的镜像加速配置
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
七、卸载
刚装好就给它卸载掉
yum remove docker-ce docker-ce-cli containerd.io ##卸载依赖
rm -rf /var/lib/docker ##删除镜像、容器