【CentOS】安装Docker教程
前提条件
Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。
首先, 查看系统是否支持:
Docker有两种方式安装:
- 脚本安装
- Yum包安装
安装前注意:
- 本文针对CentOS 7 去安装
- 如果太久或者是特殊系统不要yum update
- 必需要root权限
一、Yum包安装
(1) 添加 docker,Yum源
[root@localhost ~]# sudo tee /etc/yum.repos.d/docker.repo <<-'EOF' > [dockerrepo] > name=Docker Repository > baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/ > enabled=1 > gpgcheck=1 > gpgkey=https://yum.dockerproject.org/gpg > EOF [dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg
(2) 安装 docker包
[root@localhost ~]# yum install docker-engine
(3) 启动守护 docker进程
[root@localhost ~]# service docker start Redirecting to /bin/systemctl start docker.service
(4) 测试
[root@localhost ~]# docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1 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://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
(5) 镜像加速 (可选)
vim /etc/docker/daemon.json { "registry-mirrors": ["http://hub-mirror.c.163.com"] }
(6) 开机启动
[root@localhost ~]# systemctl enable docker.service
二、脚本安装 (感觉不太靠谱, 不推荐)
(1) yum update
(2) curl -sSL https://get.docker.com/ | sh
(3) service docker start
(4) docker run hello-world
启动时候会出现的错误:
Job for docker.service failed. See 'systemctl status docker.service' and 'journalctl -xn' for details.
1: 防火墙之类的,
2: yum -y install docker
推荐文档:
http://www.runoob.com/docker/centos-docker-install.html
http://www.docker.org.cn/book/install/supported-platform-17.html
作者:Eddie.Lee
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。