一个完整的Docker有以下几个部分组成:
DockerClient客户端
Docker Daemon守护进程
Docker Image镜像
DockerContainer容器

官方网站:https://www.docker.com/

docker操作手册:https://docs.docker.com/engine/install/centos/

 1.安装之前现在服务器上原有的docker

yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine

结果:

No Match for argument: docker

2.安装docker需要的依赖

这一步可以跟官方网站安装的操作手册一致

yum install -y yum-utils

结果:

以下结果代表该服务器已经安装最新的依赖了

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * epel: hkg.mirror.rackspace.com
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.ustc.edu.cn
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do

3.设置镜像仓库地址:

官网地址:

本地使用没成功,建议使用下面的阿里云的

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

阿里云镜像仓库地址:

 yum-config-manager \
  --add-repo \
   http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

4.安装docker相关引擎

我们这里安装的是ce版本是免费的社区版本,ee是企业版本收费比较贵

 	yum makecache fase 
yum install docker-ce docker-ce-cli containerd.io

5.启动运行docker

systemctl  start  docker

6.查看docker版本

docker version

结果:

Client: Docker Engine - Community
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:04:24 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:02:38 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.10
  GitCommit:        770bd0108c32f3fb5c73ae1264f7e503fe7b2661
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

7.使用最经典的hello,world进行测试是否执行成功

docker run hello-world

结果:

Unable to find image 'hello-world:latest' locally    运行hello-world镜像
latest: Pulling from library/hello-world             没有在本地找到hello-world镜像
2db29710123e: Pull complete                          使用pull远程在官方拉取hello-world镜像


Digest: sha256:faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af
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/

8.docker run运行思维导图

9.查看本机有哪些docker镜像

docker images

 结果:

可以看到刚才在执行docker run hello-world的时候,已经将hello-world镜像拉去到本地镜像中了

REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   14 months ago   13.3kB

10.如何卸载docker

yum  remove docker-ce docker-ce-cli containerd.io

删除资源

rm -rf  /var/lib/docker 

注意:/var/lib/docker 为docker默认的工作路径!

11.使用阿里云加速
#登录阿里云找到容器服务

在这里插入图片描述

#找到镜像加速器地址,每个阿里云用户的镜像加速地址都不一样

 

配置使用:

mkdir -p /etc/docker

tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://kskdqwg1.mirror.aliyuncs.com"]
}
EOF

 systemctl daemon-reload
 systemctl restart docker

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐