• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >虚拟化 > 在CentOS 7上安装Docker环境的方法与注意事项

在CentOS 7上安装Docker环境的方法与注意事项

作者: 字体:[增加 减小] 来源:互联网

本文主要包含CentOS7,Docker等服务器相关知识,希望可以进行参考

官网文档:https://docs.docker.com/engine/installation/linux/centos/ ,本文大部分是照搬官方文档写的,如果你英文还不错,那么就直接移步官方文档吧,如果你英文实在是不行,那就勉强看一下本人这生涩的翻译~

以下操作均在root用户下完成

docker的安装要求64位系统且内核版本大于3.10。所以如果是centos的话,必须安装CentOS7.0或以上版本。
我们这里使用的是CentOS7.2 mininul。

uname -r
3.10.0-327.28.3.el7.x86_64

安装docker前执行一下全系统的软件版本升级:
yum -y update

1.配置yum软件库

为保证安装的成功,首先使用yum update更新Yum包,表示我的好多yum包都需要更新,1500+的包,如果你像我一样好久没有更新过,那就耐心等候吧。
然后在yum软件库中新增docker的配置:

# tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

2.安装Docker

有了yum软件库的配置之后,安装也变得异常的简单,只需要以下一句即可:

# yum install docker-engine

3.启动Docker
一切就绪之后,使用start命令来启动Docker守护进程:

# service docker start

4.输出hello-world
程序员貌似跟hello-world有仇,有事儿没事就打印人家一下,玩docker咱们当前也不例外,先来个hello-world吧,这里的基本原理是利用人家已经写好的hello-world镜像,下载到本地,然后把他运行起来~

使用以下命令:

# docker run hello-world

然后控制端会输出类似于如下的信息,就证明我们的docker环境安装成功了~

在这里,我第一次失败了~显示:

Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull&service=registry.docker.io: net/http: TLS handshake timeout.
See 'docker run --help'.

然后我又来了一次就好了,应该是墙的原因吧,看着是网络访问失败了~

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete 
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
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.
 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/

设置为自启动:

chkconfig docker on

调整docker数据目录:

把一个独立的数据分区设置为docker数据目录,需手工把docker原目录的数据都移到新的存储分区上去,然后以新的存储分区挂载到/var/lib/docker目录下。

service docker stop

拷数据及挂分区:

service docker start

4、创建一个专用的docker group

docker是需要使用root权限运行的,但仍然可以通过创建一个专用的用户组的方式,让一个具备sudo权限的普通用户管理docker服务。

# groupadd docker
# usermod -aG docker bjxtb

退出当前会话,重新登录后使用bjxtb直接管理docker:

$ docker run hello-world

运行一个 Docker 容器:

[root@localhost ~]# docker run -i -t centos /bin/bash
[root@dbf66395436d /]#

我们可以看到,CentOS 容器已经被启动,并且我们得到了 bash 提示符。在 docker 命令中我们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。若要断开与容器的连接,输入 exit。

[root@cd05639b3f5c /]# cat /etc/RedHat-release
CentOSLinux release 7.0.1406(Core)
[root@cd05639b3f5c /]#exit
exit
[root@localhost ~]#

我们还可以搜索基于 Fedora 和 Ubuntu 操作系统的容器。

[root@localhost ~]# docker search ubuntu
[root@localhost ~]# docker search fedora

显示当前正在运行容器的列表

您可能感兴趣的文章:

  • Ubuntu Docker 的安装部署及简单应用
  • 在Mac OS上安装Vagrant和Docker的教程
  • CentOS7 安装docker 解决启动不了的问题
  • docker kubernetes dashboard安装部署详细介绍
  • centos7 安装docker步骤详细介绍
  • 在docker上安装运行mysql实例
  • 在windows下的安装Docker的教程
  • 在Ubuntu 16.04安装与使用Docker的教程详解
  • Docker的安装方法及运行Docker Swarm模式的使用
  • WIN10下安装Docker的教程
  • Docker简单安装与应用入门教程
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • VMware14 上安装CentOS 7 图文教程
  • CentOS 7中搭建KVM虚拟化平台的方法步骤
  • CentOS7虚拟机安装并配置docker套件
  • centos7更改docker仓库的方法
  • Centos7下安装与卸载docker应用容器引擎的方法
  • CentOS7.2服务器上搭建Docker私有镜像仓库操作示例
  • VMWare 虚拟机Centos7安装Oracle数据库的教程图解
  • centos7搭建docker私人仓库的方法(kubernetes)
  • CentOS7.2下安装docker容器教程
  • VirtualBox下CentOS7网络配置教程(可连外网)

相关文章

  • Xen虚拟机的详细迁移步骤详解
  • vmware 12 安装 mac os 10.12正式版的教程
  • Oracle VM VirtualBox 在linux系统下安装增强插件实现访问主机的共享文档方法
  • 详解mac下通过docker搭建LEMP环境
  • Docker常用的清除容器镜像命令小结
  • 在Window 10上安装Docker图文教程
  • Docker 搭建 Tomcat 运行环境的方法
  • 详解Docker与FastDFS的安装命令及使用
  • Virtual Box的host-only网络,文件共享
  • Docker使用Dockerfile创建支持ssh服务自启动的容器镜像

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • Docker 搭建 Tomcat 运行环境的方法
    • 解决ubuntu下vi上下左右方向键出现字母backspace键不能删除字符 问题
    • Docker常用的清除容器镜像命令小结
    • Docker 搭建lamp应用实例详解
    • CloudStack 创建主存储失败解决方案
    • CentOS7.2下安装docker容器教程
    • docker 如何搭建私有仓库(ubuntu 14.04,Docker版本1.6.4)详细介绍
    • Docker 私有仓库恢复实例详解
    • Docker创建运行多个mysql容器的方法示例
    • 无桌面的linux安装VMWare Tools配置教程

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有