您的位置:首页 > 运维架构 > Docker

Centos7-64位系统安装Docker

2017-07-18 09:56 603 查看
一、直接在线安装(有楼梯的话选择)

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[/code] 
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-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pulling fs layer
docker: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/18/1815 c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57/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-eth0
DEVICE='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的DNS
DNS2=114.114.114.114  #电信的DNS
# service network restart


再次启动即可:

[root@VM_162_135_centos ~]# docker run hello-world
WARNING: 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 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/[/code] 
对于: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-world

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 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/[/code] 
到此Docker安装完成!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  centos docker