Centos下安装docker教程

 更新时间:2016年02月04日 08:59:54   投稿:hebedich  
本文给大家介绍的是在centos下安装docker的详细教程,分为yum安装和脚本安装2种方式,有需要的小伙伴可以参考下。

通过yum安装

需要root或者能sudo的权限

yum包更新到最新

$ sudo yum update

添加Docker yum源

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

安装Docker包

$ sudo yum install docker-engine

启动Docker守护进程

$ sudo service docker start

通过测试镜像运行一个容器来验证Docker是否安装正确

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
  latest: Pulling from hello-world
  a8219747be10: Pull complete
  91c95931e552: Already exists
  hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
  Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd1.7.1cf5daeb82aab55838d
  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.
      (Assuming it was not already locally available.)
   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


  For more examples and ideas, visit:
   http://docs.docker.com/userguide/

通过脚本安装

需要root或者能sudo的权限

yum包更新到最新

$ sudo yum update

运行Docker安装脚本

$ curl -sSL https://get.docker.com/ | sh

这个脚本会添加docker.repo仓库并且安装Docker

启动Docker守护进程

$ sudo service docker start

通过测试镜像运行一个容器来验证Docker是否安装正确

$ sudo docker run hello-world

创建一个Docker用户组

docker守护进程绑定在Unix socket 而不是 TCP 端口。默认情况下Unix socket属于root用户和具有sudo权限用户的使用范畴。出于这个原因,docker守护进程需要一直在root用户下面运行。

To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

为了避免运行docker命令的时候需要使用sudo命令,创建一个叫docker的Unix用户组并将需要运行docker的用户添加进去。当开始运行docker守护进程,会令docker用户组的成员拥有Unix socket的读写权限。

创建docker用户组并添加用户:

1.需要root或者能sudo的权限
2.创建docker用户组并添加用户

sudo usermod -aG docker your_username

3.退出并且登录到your_username,如果在your_username下也建议退出再重新登录一次,这确保您的用户正在运行正确的权限。
4.验证运行docker已不再需要sudo命令

$ docker run hello-world

开机运行docker

$ sudo chkconfig docker on

相关文章

  • 安装harbor作为docker镜像仓库的问题

    安装harbor作为docker镜像仓库的问题

    这篇文章主要介绍了安装harbor作为docker镜像仓库,主要包括docker和docker-compose离线部署,安装harbor作为本地的仓库,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-06-06
  • 通过Dockerfile构建Docker镜像的方法步骤

    通过Dockerfile构建Docker镜像的方法步骤

    这篇文章主要介绍了通过Dockerfile构建Docker镜像的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-02-02
  • Docker容器网络端口配置过程详解

    Docker容器网络端口配置过程详解

    这篇文章主要介绍了Docker容器网络端口配置过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-10-10
  • 释放Docker占用的存储空间的几种方法

    释放Docker占用的存储空间的几种方法

    随着Docker的广泛应用,我们经常会遇到Docker占用过多存储空间的问题,这可能是由于频繁的镜像拉取、容器创建和删除等操作导致的,本文将介绍几种方法来有效释放Docker占用的存储空间,需要的朋友可以参考下
    2024-06-06
  • 云原生自动化应用于docker仓库私有凭据secret创建

    云原生自动化应用于docker仓库私有凭据secret创建

    这篇文章主要为大家介绍了云原生自动化应用于docker仓库私有凭据secret创建,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-03-03
  • 在Docker中构建并运行Nginx容器的完整教程

    在Docker中构建并运行Nginx容器的完整教程

    Docker 作为一种强大的容器化平台,使得开发、测试和部署变得更加高效和灵活,Nginx 是一款广泛使用的高性能 Web 服务器和反向代理服务器,适用于各种场景,在本教程中,我们将详细介绍如何在 Docker 中构建并运行一个 Nginx 容器,需要的朋友可以参考下
    2024-09-09
  • 搭建Docker私有镜像仓库的实现步骤

    搭建Docker私有镜像仓库的实现步骤

    私有镜像仓库可以更好地管理和控制镜像的访问和使用,提高开发和部署效率,减少网络延迟和不稳定因素的影响,本文主要介绍了搭建私有镜像仓库,感兴趣的可以了解一下
    2024-12-12
  • 使用Docker快速搭建你的Gitbook

    使用Docker快速搭建你的Gitbook

    这篇文章主要介绍了使用Docker快速搭建你的Gitbook的相关资料,需要的朋友可以参考下
    2023-11-11
  • centOS7安装docker的详细步骤

    centOS7安装docker的详细步骤

    这篇文章主要为大家介绍了centOS7安装docker的详细步骤,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-07-07
  • CentOS 7上安装Docker 1.8 的步骤详解

    CentOS 7上安装Docker 1.8 的步骤详解

    本文分步骤给大家介绍了CentOS 7上安装Docker 1.8 的步骤详解,需要的朋友可以参考下
    2018-11-11

最新评论