centos8-stream安装docker(最新)

安装依赖包

sudo yum install -y yum-utils

使用国内镜像源

sudo yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

需要测试版docker 执行:

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

安装docker

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

CentOS8设置

sudo firewall-cmd --permanent --zone=docker --change-interface=docker0
sudo systemctl restart firewalld

启动

$ sudo systemctl enable docker
$ sudo systemctl start docker

建立用户组

建立docker用户组

sudo groupadd docker

将当前用户加入用户组

sudo usermod -aG docker $USER

退出终端重新登录

测试是否安装成功

docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:7d246653d0511db2a6b2e0436cfd0e52ac8c066000264b3ce63331ac66dca625
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://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

输出如上则安装正确

镜像加速

如果在使用过程中发现拉取 Docker 镜像十分缓慢,可以配置 Docker 国内镜像加速

/etc/docker/daemon.json中写入(没有就新建)

{
  "registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com",
    "https://xxxxxx.mirror.aliyuncs.com/"
  ]
}

注意json格式
重启服务

sudo systemctl daemon-reload
sudo systemctl restart docker

执行docker info结果中包含下面内容则配置成功

Registry Mirrors:
 https://hub-mirror.c.163.com/
 https://mirror.baidubce.com/
 https://xxxx.mirror.aliyuncs.com/

安装docker-compose

二进制文件 x86_64

$ sudo curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

# 国内用户可以使用以下方式加快下载
$ sudo curl -L https://download.fastgit.org/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

$ sudo chmod +x /usr/local/bin/docker-compose
docker-compose -v

查看是否安装成功

参考文档

1.Docker - 从入门到实践
2.Docker 官方安装文档
3.docker-socket-failed-with-result-service-start-limit-hit-after-protecting-doc

你可能感兴趣的:(服务器,docker,容器,运维)