安装docker过程记录

安装docker过程记录

记录我的安装docker的过程。

0. 基础环境

基础操作系统环境为:centos7.9,无任何安装的aliyun ECS服务器

1. 安装

首先,清理可能存在的docker软件,如果不存在,执行一次也没有坏处。

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

然后,安装docker

yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 
yum makecache fast
yum install -y docker-ce docker-ce-cli containerd.io

此时docker安装完成。

2. 验证

验证安装结果:

# 执行docker 查看版本
docker version
# 返回值中可以看到docker版本信息,最后一行信息通常为docker没有启动造成
Client: Docker Engine - Community
 Version:           20.10.11
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        dea9396
 Built:             Thu Nov 18 00:38:53 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

3. 启动docker服务

# 启动docker
systemctl start docker
# docker随系统自启动
systemctl enable docker
# 命令返回内容;
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

# 其他相关命令
# 停止docker
# systemctl stop docker
# 重启docker
# systemctl restart docker

再次验证docker信息

docker version

返回内容:

Client: Docker Engine - Community
 Version:           20.10.11
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        dea9396
 Built:             Thu Nov 18 00:38:53 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.11
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.9
  Git commit:       847da18
  Built:            Thu Nov 18 00:37:17 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

可以看到,此时docker启动,不仅客户端(client)的内容可以看到,服务端(server)信息也可以看到了。

4.更换镜像地址

为了更快的下载docker镜像,更换docker镜像地址,使用anliyun的镜像。

首先需要注册一个阿里云账号。

然后进入控制台,搜索“容器镜像服务”。结果中,左侧菜单可找到“镜像加速器”。点开,里面有centos的具体操作。

主要步骤如下:

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://ddddd.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

其中镜像地址"https://ddddd.mirror.aliyuncs.com"需要替换为合理的地址

5. 执行hello-world

最后,执行一个docker的hello-world,证明环境可用,且拉取镜像的时间可接受。

docker run -it hello-world

返回结果可看到

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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/

包含了上面5行的镜像拉取过程,以及后面的镜像执行过程。

6. 清理环境

最后,清理环境,删除执行镜像的痕迹。

# 查看正在执行的容器
docker ps
# 查看已经停止的容器
docker ps -a
# 移除容器
docker rm 9aa12d18a9d5
# 查看镜像
docker images
# 移除镜像,移除前必须确保由这个镜像启动的容器已经被移除
docker rmi hello-world

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值