CentOS7安装Docker-CE

参考官方文档:https://docs.docker.com/install/linux/docker-ce/centos/linux

环境介绍docker

系统版本:CentOS Linux release 7.5.1804 (Core)
内核版本:Linux localhost.localdomain 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux



安装前准备工做:json

卸载清理原有docker程序(若是以前没安装过docker能够不用执行)ubuntu

$ 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


安装依赖软件(yum-utils提供yum-config-manager包,用来管理yum配置文件;lv2和device-mapper-persistent-data为dockerdevicemapper存储设备的必须依赖)  vim

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

 添加docker-ce安装源centos

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

 

默认开启的是stable稳定版仓库,若是想要安装test测试版或者是边缘版本可以使用以下命令开启相关模式,关闭的话只须要将--enable参数换成--disablebash

 $ sudo yum-config-manager --enable docker-ce-edge
 $ sudo yum-config-manager --enable docker-ce-test




开始安装:app

安装docker-CE(默认安装的是最新版本的稳定版)dom

$ sudo yum install docker-ce

 

若是要安装特定版本的docker-CE请使用以下命令格式:ide

$ sudo yum install docker-ce-<VERSION STRING>

查看版本列表请使用以下命令:

$ yum list docker-ce --showduplicates | sort -r

配置:

配置docker服务开机启动

$ sudo systemctl enable docker

 

配置镜像加速器:(docker的配置文件为/etc/docker/daemon.json,默认没有daemon.json,须要手动建立,镜像加速地址我用的是阿里云的)

$ sudo echo {"registry-mirrors": ["你的镜像地址"]} > /etc/docker/daemon.json
$ sudo systemctl daemon-reload


  

使用dcoker:

启动docker

$ sudo systemctl start docker


运行第一个容器:

$ sudo docker run hello-world

该命令会自动下载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/

 

问题汇总:

1.报错”WARNING: IPv4 forwarding is disabled. Networking will not work

缘由:未开启ipv4转发

解决办法:


#编辑文件
vim /etc/sysctl.conf
#配置转发
net.ipv4.ip_forward=1
#重启服务,让配置生效
systemctl restart network
#查看是否成功,若是返回为“net.ipv4.ip_forward = 1”则表示成功
sysctl net.ipv4.ip_forward
相关文章
相关标签/搜索