2.0docker环境的各种搭建方法

在centos上安装docker

前提条件

1.移除老版本docker及相关依赖

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

2.安装docker所需要的包

$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

3.使用如下命令添加稳定的仓库

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

步骤

1.安装最新版本的docker

$ sudo yum install -y docker-ce docker-ce-cli containerd.io

2.启动docker

$ sudo systemctl start docker

3.为了验证docker是否安装成功,我们启动一个hello world的容器,输出如下信息则证明安装成功。

[root@master2 vagrant]# docker run hello-world

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/

若要设置docker开机自启动,可通过如下命令:

sudo systemctl enable docker

镜像源加速

很多网上流传广的源都挂了,或者很久没更新,网易,清华等.导致还是从官方去拉取镜像,多半会碰到TLS handshake timeout的问题.

目前最快: https://docker.m.daocloud.io/

更新: /etc/docker/daemon.json

{
    "registry-mirrors": [
        "https://docker.m.daocloud.io",
        "https://docker.nju.edu.cn",
        "https://dockerproxy.com"
    ]
}

之后重启docker.

重启 docker 后通过docker info检查源是否替换成功

 Registry Mirrors:
  https://docker.m.daocloud.io/
  https://docker.nju.edu.cn/
  https://dockerproxy.com/

参考

docker官方文档

docker之设置开机自启动(二)

2024 年 4 月可以用的 docker 国内源 - 知乎 (zhihu.com)

Last updated

Was this helpful?