CentOS搭建docker

参考文档
硬件配置

  • CentOS 7.6
  • 8G Memory

使用yum安装

准备工作,查询并卸载旧版本的docker

#查询本机存在的docker
rpm qa|grep docker

#卸载旧版本的docker
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

1、安装依赖

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

2、添加docker源

sudo yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo

# 官方源
# https://download.docker.com/linux/centos/docker-ce.repo

# 测试版本的docker
# yum-config-manager --enable docker-ce-test

# 每日构建版本的docker
# yum-config-manager --enable docker-ce-nightly

yum makecache fast

3、安装docker

yum install docker-ce

4、启动docker并设置为自启动

systemctl enable docker
systemctl start docker

5、测试docker

docker run hello-world

常见错误
oci runtime error: container_linux.go:247: starting container process caused "process_linux.go:258 系统内核太低,尝试升级系统后解决此问题
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? docker守护进程没有在运行中 systemctl start docker 启动docker-daemon

成功

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
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/

失败一

Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'

出现以上信息,说明无法常速访问docker-Hub,通过配置docker镜像加速器来解决这个问题

配置CentOS镜像
vim /etc/docker/daemon.json
添加以下内容

{
  "registry-mirrors": [
    "https://registry.docker-cn.com"
  ]
}

也可替换为 https://j0andt2p.mirror.aliyuncs.com/(阿里云docker-加速)
请注意保持json格式,否则会出现docker无法启动的问题
重启docker

systemctl daemon-reload
systemctl restart docker

至此镜像配置完毕,重新执行docker run hello-world

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 现在的孩子,都是父母们掌心的宝,家长们不会再向以前一样给孩子灌输“吃亏是福”的观念,反而在孩子受到欺负的时候,告诉...
    吴晓梅阅读 623评论 1 2
  • Implement a basic calculator to evaluate a simple express...
    matrxyz阅读 391评论 0 0
  • 第四十章 舒茗醒来时发现自己正躺在一处榻上,屋子很干净,虽然不像清风阁那么华丽,却也还算是雅致非凡 “丫头,你醒了...
    清梦飞扬阅读 291评论 0 0
  • 要出差十来天,临行前照例把我家米爷送到院儿里的韩阿姨家请她代为照顾。我跟韩阿姨是因猫结识的,现在她已成米爷的“猫姥...
    爱生活的刺猬阅读 347评论 0 4