CentOS7安装Docker-CE

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

环境介绍

系统版本: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



安装前准备工作:

卸载清理原有docker程序(如果之前没安装过docker可以不用执行)

$ 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存储设备的必须依赖)  

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

 添加docker-ce安装源

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

 

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

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




开始安装:

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

$ sudo yum install docker-ce

如果要安装特定版本的docker-CE请使用如下命令格式:

$ 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/

 

 

 

 

 


猜你喜欢

转载自blog.51cto.com/wangxiaoke/2174103