【centos7】安装docker

下面是安装docker-communtiy版本的方法。

参考:
https://docs.docker.com/install/linux/docker-ce/centos/#upgrade-docker-after-using-the-convenience-script

1. 清除可能存在的老版本

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

2. 下载rpm文件

  1. containerd.io-1.2.0-3.el7.x86_64.rpm
  2. docker-ce-cli-18.09.0-3.el7.x86_64.rpm
  3. docker-ce-18.09.0-3.el7.x86_64.rpm

下载页面: https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

分别对如上文件进行安装

sudo yum install containerd.io-1.2.0-3.el7.x86_64.rpm
sudo yum install docker-ce-cli-18.09.0-3.el7.x86_64.rpm
sudo yum install docker-ce-18.09.0-3.el7.x86_64.rpm

3. 设置docker deamon自启动

[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

4. 镜像加速

国内连接Docker hub网络情况不佳,我们可以考虑国内提供加速服务的公司,目前有阿里云和daoCloud的加速,下面已daocloud的镜像加速为例。

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

该脚本可以将 --registry-mirror 加入到你的 Docker 配置文件 /etc/docker/daemon.json 中。适用于 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1,其他版本可能有细微不同。更多详情请访问文档。

5. 启动Docker

systemctl start docker

6. 示例

[root@localhost docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete 
Digest: sha256:523e382ab1801f2a616239b1052bb7ee5a7cce6a06cfed27ccb93680eacad6ef
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/

你可能感兴趣的:(Linux)