Docker安装教程(CentOS7)

Docker安装教程(CentOS7)

系统要求

Docker CE要求Linux内核版本不得低于3.10,本教程使用的CentOS7 x64版本的系统,刚好符合最低要求。

卸载旧版本

为了确保安装的Docker版本,首先我们需要先将系统上旧的Docker版本卸载掉。

$ sudo yum remove docker*

使用yum进行安装

执行以下命令安装依赖包:

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

添加yum软件源

执行以下命令安装软件源,由于国内网络的特殊情况,本次使用的是阿里的软件源:

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

更新并安装Docker CE

执行以下命令:

$ sudo yum makecache fast
$ sudo yum -y install docker-ce

启动Docker CE

$ sudo systemctl enable docker
$ sudo systemctl start docker

测试Docker是否安装正确

$ docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

输出以上信息为正确安装。

添加内核参数

默认配置下,如果在CentOS使用Docker CE看到以下警告信息:

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

请添加内核配置参数以启用这些功能

$ sudo tee -a /etc/sysctl.conf <<-EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
EOF

然后重新加载sysctl.conf即可

$ sudo sysctl -p
发布了4 篇原创文章 · 获赞 1 · 访问量 6048

猜你喜欢

转载自blog.csdn.net/RisenMyth/article/details/104440706