Docker学习一 Docker社区版安装

Docker社区版安装–CENTOS 7

前言

Docker至今为止已经非常火了,不管是运维,还是后端开发都用得到。首先安装一版试试吧。

参考菜鸟教程进行安装,并解决一些可能遇到的问题。

环境

  • 操作系统:CentOS 7.6
  • 操作用户:root
  • 安装时间:2020年5月21日

卸载旧版本

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

安装 Docker Engine-Community

使用 Docker 仓库进行安装

在新主机上首次安装 Docker Engine-Community 之前,需要设置 Docker 仓库。之后,您可以从仓库安装和更新 Docker。

设置仓库

安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。

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

使用以下命令来设置稳定的仓库。

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

安装 Docker Engine-Community

安装最新版本的 Docker Engine-Community 和 containerd:

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

安装结果

[root@gxp5 default]# yum list installed |grep docker
containerd.io.x86_64                    1.2.13-3.2.el7                 @docker-ce-stable
docker-ce.x86_64                        3:19.03.9-3.el7                @docker-ce-stable
docker-ce-cli.x86_64                    1:19.03.9-3.el7                @docker-ce-stable

启动 Docker。

sudo systemctl start docker

通过运行 hello-world 映像来验证是否正确安装了 Docker Engine-Community 。

sudo docker run hello-world

WARNING: IPv4 forwarding is disabled. Networking will not work.
Hello from Docker!
This message shows that your installation appears to be working correctly.
...

安装遇到的问题

下载hello-world失败

[root@gxp5 docker]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
...

本地没有hello-world,且长时间下载不下来,报超时。通过添加稳定的国内docker源解决。

  1. 在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件):
{  
    "registry-mirrors": [    
        "https://dockerhub.azk8s.cn",    
        "https://reg-mirror.qiniu.com",    
        "https://registry.docker-cn.com"  
    ] 
}
  1. 重启docker
sduo systemctl restart docker

配置文件/etc/sysconfig/docker不存在

  1. 修改service文件
vim  /lib/systemd/system/docker.service

在[Service]中添加一行EnvironmentFile=/etc/sysconfig/docker

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
  1. 新增配置文件 vim /etc/sysconfig/docker
# /etc/sysconfig/docker

# Modify these options if you want to change the way the docker daemon runs
OPTIONS='-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock'
DOCKER_CERT_PATH=/etc/docker

# If you want to add your own registry to be used for docker search and docker
# pull use the ADD_REGISTRY option to list a set of registries, each prepended
# with --add-registry flag. The first registry added will be the first registry
# searched.
# ADD_REGISTRY='--add-registry registry.access.redhat.com'

# If you want to block registries from being used, uncomment the BLOCK_REGISTRY
# option and give it a set of registries, each prepended with --block-registry
# flag. For example adding docker.io will stop users from downloading images
# from docker.io
# BLOCK_REGISTRY='--block-registry'

# If you have a registry secured with https but do not have proper certs
# distributed, you can tell docker to not look for full authorization by
# adding the registry to the INSECURE_REGISTRY line and uncommenting it.
 INSECURE_REGISTRY='--insecure-registry dl.dockerpool.com:5000'

# On an SELinux system, if you remove the --selinux-enabled option, you
# also need to turn on the docker_transition_unconfined boolean.
# setsebool -P docker_transition_unconfined 1

# Location used for temporary files, such as those created by
# docker load and build operations. Default is /var/lib/docker/tmp
# Can be overriden by setting the following environment variable.
# DOCKER_TMPDIR=/var/tmp

# Controls the /etc/cron.daily/docker-logrotate cron job status.
# To disable, uncomment the line below.
# LOGROTATE=false
  1. 重启docker
systemctl daemon-reload
systemctl restart docker
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值