Centos7-64位系统安装Docker

来源:互联网 发布:删除手机预装软件 编辑:程序博客网 时间:2024/06/07 00:07

一、直接在线安装(有楼梯的话选择)
1、安装依赖包:yum install -y yum-utils device-mapper-persistent-data lvm2
2、安装稳定的仓库:

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

3、安装Docker(社区版)
a)更新yum的索引:yum makecache fast
b)安装最新版的Docker:yum install docker-ce
c)查看版本(安装版本排序):yum list docker-ce.x86_64 --showduplicates | sort -r
d)安装指定版本的Docker:yum install docker-ce-<VERSION>
4、启动Docker:systemctl start docker
5、测试:docker run hello-world
6、要升级Docker CE,首先快速运行sudo yum makecache,然后按照安装说明,选择要安装的新版本。

二、手动下载安装包
1、到https://download.docker.com/linux/centos/7/x86_64/stable/Packages/并下载要安装的Docker版本的.rpm文件。
2、安装:yum install /path/to/package.rpm
3、启动:systemctl start docker
4、测试:docker run hello-world
三、卸载:
1、卸载Docker软件包: yum remove docker-ce
2、删除所有图像,容器和卷:rm -rf /var/lib/docker
四、可能会出现的异常:

[root@VM_162_135_centos ~]# docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-worldb04784fba78d: Pulling fs layer docker: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/18/1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57/data?Expires=1500279939&Signature=TTj25I73aNR5f1NMrIGFVQNX9KS99JpEn9Dd6V4XOK-Z5FLPX2gKv2kg6fubYPr-FIqnASwZ0fNzj600XQ5zv7uSEtbnXdKHu18FcjVM3eJ~df6bXWqcJml9QqiF07ZHm0udzIOpr2tVD64YFFeNvw~1pJKBpAHTA2th~V1gpa8_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q: net/http: TLS handshake timeout.See 'docker run --help'.

解决方案:

#vim /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE='eth0'NM_CONTROLLED='yes'ONBOOT='yes'IPADDR='10.104.162.135'NETMASK='255.255.192.0'GATEWAY='10.104.128.1'#新增以下代码DNS1=8.8.8.8            #Google的DNSDNS2=114.114.114.114  #电信的DNS# service network restart

再次启动即可:

[root@VM_162_135_centos ~]# docker run hello-worldWARNING: IPv4 forwarding is disabled. Networking will not work.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. 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 bashShare 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/

对于:WARNING: IPv4 forwarding is disabled. Networking will not work.的解决办法:

# vi /etc/sysctl.conf或者# vi /usr/lib/sysctl.d/00-system.conf添加如下代码:    net.ipv4.ip_forward=1重启network服务# systemctl restart network查看是否修改成功# sysctl net.ipv4.ip_forward如果返回为“net.ipv4.ip_forward = 1”则表示成功

这时启动docker时将不会显示WARNING: IPv4 forwarding is disabled. Networking will not work.

[root@VM_162_135_centos ~]#  docker run hello-worldHello 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. 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 bashShare 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/

到此Docker安装完成!