在CentOS 7中安装Docker

1-确认系统信息

# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
# uname -a
Linux CentOS-7 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

2-安装docker

# yum -y install docker

3-关闭SELinux和启动docker服务

关闭SELinux

  • 永久方法:修改/etc/selinux/config文件中设置SELINUX=disabled ,然后重启。
  • 临时方法:执行setenforce 0命令设置SELinux成为permissive模式
sudo systemctl status firewalld.service
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service

启动docker服务

[root@CentOS-7 ~]# systemctl start docker.service

设置自启动docker服务

[root@CentOS-7 ~]# systemctl enable docker.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@CentOS-7 ~]# systemctl is-enabled docker.service
enabled
[root@CentOS-7 ~]#

4-设置docker代理

# vim /etc/sysconfig/docker

根据实际需要添加相应内容

HTTP_PROXY=http://10.144.1.10:8080
#HTTPS_PROXY=https://10.144.1.10:8080
#FTP_PROXY=ftp://10.144.1.10:8080

注意:一般情况下,国内镜像设置或代理设置,只需要完成一种配置就可以了。

5-重启docker

# systemctl daemon-reload

# systemctl restart docker

6-安装验证

运行官方镜像hello-world文件

# docker run hello-world
Unable to find image 'hello-world:latest' locally
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for docker.io/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.
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 Hub account:
https://hub.docker.com For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/ #
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest c54a2cc56cbb 5 months ago 1.848 kB

另外一种Docker代理设置方法

修改docker.service文件

# vim /usr/lib/systemd/system/docker.service

在[Service]部分添加如下内容

Environment="HTTP_PROXY=http://10.144.1.10:8080"

Environment="HTTPS_PROXY=https://10.144.1.10:8080"

Environment="FTP_PROXY=ftp://10.144.1.10:8080"

或者,另外创建代理文件

# mkdir /etc/systemd/system/docker.service.d
# touch /etc/systemd/system/docker.service.d/proxy.conf
# vim /etc/systemd/system/docker.service.d/proxy.conf

增加以下内容

[Service]

Environment="HTTP_PROXY=http://10.144.1.10:8080"

Environment="HTTPS_PROXY=https://10.144.1.10:8080"

Environment="FTP_PROXY=ftp://10.144.1.10:8080"

重启docker

# systemctl daemon-reload

# systemctl restart docker

检查docker环境变量是否加载

# systemctl show docker --property Environment
Environment=GOTRACEBACK=crash HTTP_PROXY=http://10.144.1.10:8080 HTTPS_PROXY=https://10.144.1.10:8080 FTP_PROXY=ftp://10.144.1.10:8080

示例 - 在CentOS7系统安装docker并运行镜像(使用国内镜像)

[root@CentOS7 ~]# route add default gw 10.0.3.2
[root@CentOS7 ~]#
[root@CentOS7 ~]# yum -y install docker
[root@CentOS7 ~]# vim /etc/selinux/config
[root@CentOS7 ~]# cat /etc/selinux/config |grep "SELINUX="
# SELINUX= can take one of these three values:
SELINUX=disabled
[root@CentOS7 ~]#
[root@CentOS7 ~]# setenforce 0
[root@CentOS7 ~]#
[root@CentOS7 ~]# systemctl start docker.service
[root@CentOS7 ~]# systemctl enable docker.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@CentOS7 ~]# systemctl is-enabled docker.service
enabled
[root@CentOS7 ~]#
[root@CentOS7 ~]# sudo mkdir -p /etc/docker
[root@CentOS7 ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://t5t8q6wn.mirror.aliyuncs.com"]
> }
> EOF
{
"registry-mirrors": ["https://t5t8q6wn.mirror.aliyuncs.com"]
}
[root@CentOS7 ~]# systemctl daemon-reload
[root@CentOS7 ~]# systemctl restart docker
[root@CentOS7 ~]#
[root@CentOS7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@CentOS7 ~]#
[root@CentOS7 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 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/ [root@CentOS7 ~]#
[root@CentOS7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest 48b5124b2768 3 months ago 1.84 kB
[root@CentOS7 ~]#

Docker - 在CentOS7中安装Docker的更多相关文章

  1. Docker(一) - CentOS7中安装Docker - (视频教程)

    Docker的使用越来越多,安装也相对简单.本文使用视频的方式展示在CentOS7系统中安装Docker,本文更适合于准备入门学习Docker的童靴. 以下视频,请带上耳机开始聆听 (双击全屏播放) ...

  2. docker(一) Centos7下安装docker

    docker(一) Centos7下安装dockerdocker(二) windows10下安装dockerdocker(三) 镜像和容器常用命令 docker(四) 使用Dockerfile构建镜像 ...

  3. docker探索-CentOS7中配置Docker的yum源并升级安装docker1.13(十)

    此处使用的是CentOS7,内核版本为 [root@localhost ~]# uname -r -.el7.x86_64 该版本下,配置了yum的源为阿里的镜像源,具体的配置方法可以参见阿里镜像源配 ...

  4. 在Centos7中安装Docker并实例化Mysql

    首先 本文是一篇安装流程,从初始的Centos7安装Docker后实例化一个Mysql的整个流程,其中会包含一些需要注意的疑点和坑. 实例化的Mysql是将数据和配置保存在宿主机. 注意,在安装Doc ...

  5. Centos7中安装Docker

    1.配置docker镜像安装源 tee /etc/yum.repos.d/docker.repo <<-'EOF' [dockerrepo] name=Docker Repository ...

  6. Docker - 在Windows7中安装Docker

    安装docker 1 - Virtualization Support Check whether virtualization support is enabled at BIOS via HAV ...

  7. Docker - 在CentOS 7中安装Docker

    1-确认系统信息 # cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) # uname -a Linux CentOS-7 3. ...

  8. Centos7上安装docker (转)

    Centos7上安装docker Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE. 社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如 ...

  9. centos7下安装docker(14安装docker machine)

    之前我们做的实验都是在一个host上面的,其实在真正的环境中有多个host,容器在这些host上面启动,运行,停止和销毁,相关容器会通过网络相互通信,无论他们是否运行在相同的host上面. 对于这种歌 ...

随机推荐

  1. 字符编码,python解释器------总结

    目录 1. 编码: 1.字符编码 2. 编码的历史 3. 编码和解码 2. python解释器 解释代码的流程 1. 读取文本到解释器 2. 识别代码(检查语法问题) 3. 往终端打印 1. 编码: ...

  2. 081_使用 awk 编写的 wc 程序

    #!/bin/bash#自定义变量 chars 变量存储字符个数,自定义变量 words 变量存储单词个数#awk 内置变量 NR 存储行数#length()为 awk 内置函数,用来统计每行的字符数 ...

  3. 二十六. 集群及LVS简介 LVS-NAT集群 LVS-DR集群

    方案:安装ipvsadm软件包,关于ipvsadm的用法可以参考man ipvsadm资料. 常用ipvsadm命令语法格式如表-1及表-2所示. 1.ipvsadm命令用法(proxy) 1.1 创 ...

  4. NetworkX系列教程(8)-Drawing Graph

    小书匠Graph图论 如果只是简单使用nx.draw,是无法定制出自己需要的graph,并且这样的graph内的点坐标的不定的,运行一次变一次,实际中一般是要求固定的位置,这就需要到布局的概念了.详细 ...

  5. spoj Longest Common Substring (多串求最大公共子序列)

    题目链接: https://vjudge.net/problem/SPOJ-LCS 题意: 最多10行字符串 求最大公共子序列 数据范围: $1\leq |S| \leq100000$ 分析: 让他们 ...

  6. OpenJudge 1.5.14 人口增长问题

    描述 我国现有x亿人口,按照每年0.1%的增长速度,n年后将有多少人? 输入一行,包含两个整数x和n,分别是人口基数和年数,以单个空格分隔.输出输出最后的人口数,以亿为单位,保留到小数点后四位.1 & ...

  7. 面试题集锦---BY算法导论小组

    3.7题 3.21题 1.给定能随机生成整数 1 到 5 的函数,写出能随机生成整数 1 到 7 的函数. 提示:两个random就可以有25种可能,每种可能都是等概率的 2.判断一个自然数是否是某个 ...

  8. git 删除目录及子目录下的同名文件

    find . -name ".git" | xargs rm -Rf find . -name ".gitignore" | xargs rm -Rf

  9. Java 交换两数的方法

    错误示范 1. 直接交换 public class SwapNumbers { // 直接交换 public static void swap(int a, int b) { int temp = a ...

  10. mkfs格式化分区(为分区写入文件系统)

    mkfs 命令非常简单易用,不过是不能调整分区的默认参数的(比如块大小是 4096 Bytes),这些默认参数除非特殊清况,否则不需要调整.如果想要调整,就需要使用 mke2fs 命令重新格式化.命令 ...