Docker是基于Go语言实现的云开源项目。
主要目标: 通过对应用组件的封装、分发、部署、运行等生命周期的管理,使用户的APP及其运行环境能够做到“一次镜像,处处运行”。将应用打成镜像,通过Docker容器上面的实例,而Docker容器在任何操作系统上都是一致的,这就实现了跨平台,跨服武器,只需要一次配置好环境,换到别的机子上就可以一键部署好,大大简化了操作。
一句话: 解决了运行环境和配置问题的软件容器,方便做持续集成并有助于整体发布的容器虚拟化技术。
官网:https://www.docker.com
镜像官网:https://hub.docker.com/
因此:Docker必须部署在Linux内核的系统上,如果其他系统想部署Docker就必须安装一个虚拟Linux环境。
目前CentOS仅发行版本中的内核支持Docker,Docker运行在CentOS 7 (64-bit)上,要求系统为64微,内核版本为3.8+。
[root@ecs-340806 /]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@ecs-340806 /]# uname -r
3.10.0-1160.53.1.el7.x86_64
[root@ecs-340806 /]#
就是一个只读的模板。
镜像可以用来创建Docker容器,一个镜像可以创建多个容器。它也相当于一个Root文件系统。相当于容器的“源代码”,Docker镜像文件类似于Java的类模板,而Docker容器实例类似于java中new出来的实例对象。
集中存放镜像文件的场所,存放各种镜像模板的地方。
https://docs.docker.com/engine/install/centos/
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
yum -y install gcc
yum -y install gcc-c++
安装yum-utils包(提供yum-config-manager 实用程序)并设置存储库。
sudo yum install -y yum-utils
官方:设置存储库,因为网址为外网,所以经常访问超时,所以不推荐官方安装流程的命令↓
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
因此需要切换仓库,国内可以用阿里云,华为云之类
阿里云:
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
sudo yum install docker-ce docker-ce-cli containerd.io
一路 y 就可以了
执行完毕就安装Docker完成了
sudo systemctl start docker
查看docker进程,有则表示启动成功
ps -ef | grep docker
root 25652 1 0 11:32 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 25810 24142 0 11:32 pts/1 00:00:00 grep --color=auto docker
也可以使用docker version查看相关信息,表示启动成功
[root@ecs-340806 /]# docker version
Client: Docker Engine - Community
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:05:12 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:03:33 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.6
GitCommit: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc:
Version: 1.1.2
GitCommit: v1.1.2-0-ga916309
docker-init:
Version: 0.19.0
GitCommit: de40ad0
sudo docker run hello-world
本地没有helloWorld镜像所以 自动去远程库拉取运行,所以展示以下内容表示docker安装没问题
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:53f1bbee2f52c39e41682ee1d388285290c5c8a76cc92b42687eecf38e0af3f0
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/
systemctl stop docker
sudo yum remove docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
阿里云镜像加速地址
https://qdmkalkr.mirror.aliyuncs.com
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://qdmkalkr.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker