在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:latestHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto 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 Hub account:https://hub.docker.comFor 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:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7Hello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto 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/[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 ~]# 

转载于:https://www.cnblogs.com/anliven/p/6202083.html

Docker - 在CentOS 7中安装Docker相关推荐

  1. CentOS 8中安装Docker出现和Podman冲突

    感谢这位博主的文章: CentOS 8中安装Docker出现和Podman冲突_ywyngq的博客-CSDN博客https://blog.csdn.net/ywyngq/article/details ...

  2. centos 7 中安装 docker和创建 tomcat容器并部署web应用

    在 CentOS 7 中安装 Docker 和创建 Tomcat 容器并部署Web应用 一般部署Web应用都需要安装数据库,比如 MySQL 和 Redis,MySQL 和 Redis 属于多个Web ...

  3. 在 CentOS 7 中安装 Docker

    1.安装环境 此处在Centos7进行安装,可以使用以下命令查看CentOS版本 lsb_release -a 在 CentOS 7安装docker要求系统为64位.系统内核版本为 3.10 以上,可 ...

  4. win7 docker centos安装mysql_win7下docker环境centos容器中安装mysql5.7

    docker环境基于镜像skiychan/nginx-php7,进行安装 ps:skiychan/nginx-php7此镜像已封装nginx1.15.3+php7.2.9 1.环境配置 配置共享文件夹 ...

  5. 华为云服务器CentOS 8.2 安装docker

    1.安装docker yum install docker 2.启动服务(可能会报错) 报错: Failed to start docker.service: Unit docker.service ...

  6. Centos中安装docker并查看拉取镜像的位置

    此操作全程在root用户下执行 一.docker安装 执行以下命令将yum包更新到最新版本 yum update 下载docker所需的软件包 yum install -y yum-utils dev ...

  7. abp 打包部署到ubuntu_如何在Ubuntu中安装Docker和运行 Docker容器

    Docker是一种开源且流行的操作系统级虚拟化(俗称"容器化")技术,主要在Linux和Windows上运行. Docker使用容器可以更轻松地创建,部署和运行应用程序. 使用容器 ...

  8. 如何在CentOS 8上安装Docker

    介绍 与之前的版本相比,新的CentOS 8版本引入了许多创新元素,一个重大变化是决定不再为Docker提供官方支持. 相反,RHE选择引入用于容器映像创建和管理的内置工具:buildah和podma ...

  9. Centos安装Docker详细步骤,Debian安装Docker详细步骤

    Linux 安装Docker指令 1. Centos安装Docker 更新系统: sudo yum update 安装依赖包,以便使用 HTTPS 连接下载 Docker 软件包: sudo yum ...

最新文章

  1. 远程注入dll中注册热键
  2. KMP算法的动态规划解说
  3. 认证(登录)功能实现
  4. python从视频中提取音频_提取视频中的音频——python三行程序搞定!
  5. “是男人就下100层”
  6. 1024程序员日,互联网公司们福利感人;支付宝36万招“找茬”程序员
  7. matlab的repmat函数和mean函数,sum函数
  8. 联合查询(union)——MySQL
  9. Siebel Open UI
  10. android 科大讯飞语音播报简单集成
  11. 软件用户手册(软件使用说明书)
  12. python编码格式 兼容中文_python中文编码(汉字乱码问题解决方案)
  13. redis关于hash的常用命令
  14. OpenSSH: 通过 LDAP 做认证
  15. FIFO就是 first in first out 先进先出
  16. 一加5Android8.0刷机包,一加手机1安卓8.0刷机包放出:刷机小王子神话不灭
  17. 计算机函数sun怎么用,手把手演示sumif函数怎么用【处置步骤】
  18. leetcode学习笔记之07Revers Integer(整数反转)
  19. pylon保存图片_pylon界面中文说明-德国basler工业相机.pdf
  20. 为什么光盘能安装 gpt_您需要了解有关gpt 3的哪些信息以及为什么如此重要

热门文章

  1. MKL学习——向量操作
  2. Kubernetes系列之Helm介绍篇
  3. 爬取网页的通用代码框架
  4. [BZOJ] 1688: [Usaco2005 Open]Disease Manangement 疾病管理
  5. 猴子吃桃问题(南阳ACM324)
  6. 博客园win8客户端开发记录5-app设置 登录 回复评论
  7. 设计模式学习-工厂方法模式
  8. javaScript第六天(2)
  9. sudo: pip:找不到命令
  10. 【C语言及程序设计】项目2-15:模块化的简单银行系统设计