> 文档中心 > Docker - CentOS7下安装Docker篇

Docker - CentOS7下安装Docker篇

目录

    • 设置阿里云镜像加速器
    • Docker 安装
      • 如果想安装不同的版本
      • 设置Docker默认存储目录

设置阿里云镜像加速器

sudo cp -n /lib/systemd/system/docker.service /etc/systemd/system/docker.servicesudo sed -i "s|ExecStart=/usr/bin/docker daemon|ExecStart=/usr/bin/docker daemon --registry-mirror=|g" /etc/systemd/system/docker.servicesudo sed -i "s|ExecStart=/usr/bin/dockerd|ExecStart=/usr/bin/dockerd --registry-mirror=|g" /etc/systemd/system/docker.servicesudo systemctl daemon-reloadsudo service docker restart

Docker 安装

Step 1: 安装yum-utils

  sudo yum install -y yum-utils

Step 2: 设置为阿里云镜像

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

Step 3: 直接安装最新docker版本

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

Step 4: 安装完成后查看版本

docker -v

如果想安装不同的版本

Step 1: 列出可用版本

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

Step 2: 安装指定版本

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

比如:

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

PS: 我就不教各位怎么卸载了(问就是不会)

设置Docker默认存储目录

安装之后默认存储目录/var/lib/docker,空间会越来越少, 我们把它放到home下:

vim /usr/lib/systemd/system/docker.service

编辑:

[Unit]Description=Docker Application Container EngineDocumentation=https://docs.docker.comAfter=network-online.target firewalld.service containerd.serviceWants=network-online.targetRequires=docker.socket containerd.service[Service]Type=notify# the default is not to use systemd for cgroups because the delegate issues still# exists and systemd currently does not support the cgroup feature set required# for containers run by docker# 就这一行后面加上 ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:6274  --containerd=/run/containerd/containerd.sockExecReload=/bin/kill -s HUP $MAINPIDTimeoutSec=0RestartSec=2Restart=always# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.# Both the old, and new location are accepted by systemd 229 and up, so using the old location# to make them work for either version of systemd.StartLimitBurst=3# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make# this option work for either version of systemd.StartLimitInterval=60s# Having non-zero Limit*s causes performance problems due to accounting overhead# in the kernel. We recommend using cgroups to do container-local accounting.LimitNOFILE=infinityLimitNPROC=infinityLimitCORE=infinity# Comment TasksMax if your systemd version does not support it.# Only systemd 226 and above support this option.TasksMax=infinity# set delegate yes so that systemd does not reset the cgroups of docker containersDelegate=yes# kill only the docker process, not all processes in the cgroupKillMode=processOOMScoreAdjust=-500[Install]WantedBy=multi-user.target

这个就是指定默认存储目录

-–graph /home/jack/docker/home/

这个是开启Docker API,这样Idea就能远程连接Docker了

-H tcp://0.0.0.0:6274

设置Docker开机自启

systemctl enable docker

修改完docker.service,要记得重新加载一下

systemctl daemon-reload

重启Docker

systemctl restart docker

查看信息

docker info

松山湖人才网