Docker在CentOS安装文档

简介:

Docker在CentOS安装手册

这篇文档是通过Docker自己管理的发布版本包来指导你安装部署,使用这些包能确保您安装最新的Docker版本,

先决条件

Docker 需要一个64位操作系统CentOS,同时,您的内核(kernel)版本至少是3.10。

检查您当前内核的版本,打开一个终端(terminal),使用命令uname -r 来展示你的内核版本

$ uname -r
3.10.0-229.el7.x86_64
AI 代码解读

最后,建议你的系统打上最新的补丁,保证最新内核版本上已报告出来的kernel bugs都被修复啦

安装

有两种方式来安装Docker容器(Docker Engine)。你可以使用yum安装包管理器。或者使用curl通过站点get.docker.com来满足
自动化安装,第二种方法运行的安装脚本内部同样也是运用yum的方式。

YUM安装方式(Install with yum)

1.使用有sudo权限或者root权限的用户登录服务器。

2.确保你已有的yum包更新到最新版本

$ sudo yum update
AI 代码解读

3.添加yum仓库

× Linux CentOS 7 添加仓库方式

$ cat >/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
AI 代码解读

× Linux CentOS 6 添加仓库方式

$ cat >/etc/yum.repos.d/docker.repo <<-EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/6
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
AI 代码解读

4.安装Docker部署包

$ sudo yum install docker-engine
AI 代码解读

5.启动Docker进程

$ sudo service docker start
AI 代码解读

6.为了验证docker被正确安装,我们通过在容器(container)中运行一个测试镜像来检验

$ 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/
AI 代码解读

脚本安装方式(Install with the script)

1.使用有sudo权限或者root权限的用户登录服务器。

2.确保你已有的yum包更新到最新版本

$ sudo yum update
AI 代码解读

3.运行Docker安装脚本

$ curl -sSL https://get.docker.com/ | sh
AI 代码解读

这个脚本会添加docker.repo知识仓库,然后安装Docker。

4.启动Docker进程

$ sudo service docker start
AI 代码解读

5.为了验证docker被正确安装,我们通过在容器(container)中运行一个测试镜像来检验

$ sudo docker run hello-world
AI 代码解读

创建Docker组

Docker绑定Unix套接字来替换TCP端口。默认Unix套接字由root用户或者其他有sudo权限的用户拥有。由于这个原因Docker进程总是以root用户来运行。

当你使用Docker命令的时候避免你使用sudo命令,可以创建一个Unix用户组叫做docker然后把用户添加进去。当Docker进程开启后,它就可以被Docker用户组拥有,且具有读写权限。

警告:docker用户组相当于root用户组,对于你的系统产生多大的安全影响,细节
请查看Docker Daemon Attack Surface

创建Docker用户组并且添加用户

1.使用有sudo权限的用户登录CentOS

2.创建Docker用户组并且添加用户

sudo usermod -aG docker your_usernam
AI 代码解读

3.注销并重新登录

4.通过不用sudo命令验证你的docker操作

$ docker run hello-world
AI 代码解读

自启动docker进程

为了能在系统引导时启动docker进程,请做如下操作:

$ sudo chkconfig docker on
AI 代码解读

卸载

你可以通过yum卸载Docker软件

1.列出你安装过的包

$ yum list installed | grep docker
yum list installed | grep docker
docker-engine.x86_64   1.7.1-1.el7 @/docker-engine-1.7.1-1.el7.x86_64.rpm
AI 代码解读

2.移除安装包

$ sudo yum -y remove docker-engine.x86_64
AI 代码解读

这个命令并没有移除镜像,容器和卷和你的主机上配置过的配置文件

3.删除所有的镜像,容器和卷,如下:

$ rm -rf /var/lib/docker
AI 代码解读

4.定位和删除用户配置过的配置文件

目录
打赏
0
0
0
0
10
分享
相关文章
|
13天前
|
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
64 20
docker centos镜像 npm安装包时报错“npm ERR! code ECONNRESET”
通过上述步骤,您可以有效解决在 Docker 中使用 CentOS 镜像安装 npm 包时遇到的 "npm ERR! code ECONNRESET" 错误。希望这些方法能帮助您顺利进行 npm 包的安装。
116 26
《docker基础篇:3.Docker常用命令》包括帮助启动类命令、镜像命令、有镜像才能创建容器,这是根本前提(下载一个CentOS或者ubuntu镜像演示)、容器命令、小总结
《docker基础篇:3.Docker常用命令》包括帮助启动类命令、镜像命令、有镜像才能创建容器,这是根本前提(下载一个CentOS或者ubuntu镜像演示)、容器命令、小总结
177 6
《docker基础篇:3.Docker常用命令》包括帮助启动类命令、镜像命令、有镜像才能创建容器,这是根本前提(下载一个CentOS或者ubuntu镜像演示)、容器命令、小总结
|
2月前
|
CentOS停更沉寂,RHEL巨变限制源代:Docker容器化技术的兴起助力操作系统新格局
操作系统是计算机系统的核心软件,管理和控制硬件与软件资源,为用户和应用程序提供高效、安全的运行环境。Linux作为开源、跨平台的操作系统,具有高度可定制性、稳定性和安全性,广泛应用于服务器、云计算、物联网等领域。其发展得益于庞大的社区支持,多种发行版如Ubuntu、Debian、Fedora等满足不同需求。
80 5
centos系统清理docker日志文件
通过以上方法,可以有效清理和管理CentOS系统中的Docker日志文件,防止日志文件占用过多磁盘空间。选择合适的方法取决于具体的应用场景和需求,可以结合手动清理、logrotate和调整日志驱动等多种方式,确保系统的高效运行。
363 2
Centos安装docker(linux安装docker)——超详细小白可操作手把手教程,包好用!!!
本篇博客重在讲解Centos安装docker,经博主多次在不同服务器上测试,极其的稳定,尤其是阿里的服务器,一路复制命令畅通无阻。
4910 4
Centos安装docker(linux安装docker)——超详细小白可操作手把手教程,包好用!!!
|
3月前
|
docker运行centos提示Operation not permitted
通过上述步骤,可以有效排查和解决在Docker中运行CentOS容器时遇到的"Operation not permitted"错误。这些措施涵盖了从权限配置、安全策略到容器运行参数的各个方面,确保在不同环境和使用场景下都能顺利运行容器。如果你需要进一步优化和管理你的Docker环境
282 3
Docker学习二(Centos):Docker安装并运行redis(成功运行)
这篇文章介绍了在CentOS系统上使用Docker安装并运行Redis数据库的详细步骤,包括拉取Redis镜像、创建挂载目录、下载配置文件、修改配置以及使用Docker命令运行Redis容器,并检查运行状态和使用Navicat连接Redis。
552 3
Centos7下docker的jenkins下载并配置jdk与maven
通过上述步骤,您将成功在CentOS 7上的Docker容器中部署了Jenkins,并配置好了JDK与Maven,为持续集成和自动化构建打下了坚实基础。
212 1
虚拟机centos7.9一键部署docker
本文介绍了如何在 CentOS 7.9 虚拟机上安装 Docker 社区版 (Docker-ce-20.10.20)。通过使用阿里云镜像源,利用 `wget` 下载并配置 Docker-ce 的 YUM 仓库文件,然后通过 `yum` 命令完成安装。安装后,通过 `systemctl` 设置 Docker 开机自启并启动 Docker 服务。最后,使用 `docker version` 验证安装成功,并展示了客户端与服务器的版本信息。文中还提供了列出所有可用 Docker-ce 版本的命令。
355 0
虚拟机centos7.9一键部署docker