Docker 安装 CentOS
CentOS(Community Enterprise Operating System)是 Linux 发行版之一,它是来自于 Red Hat Enterprise Linux(RHEL)依照开放源代码规定发布的源代码所编译而成。由于出自同样的源代码,因此有些要求高度稳定性的服务器以 CentOS 替代商业版的 Red Hat Enterprise Linux 使用。
1. 查看可用的 CentOS 版本
访问 CentOS 镜像库地址:https://dockers.xuanyuan.me/image/library/centos
版本说明
- 默认标签是 centos:latest,代表最新版本
- CentOS 7 是目前最稳定的版本之一
- 建议在生产环境中使用稳定版本
2. 拉取指定版本的 CentOS 镜像
这里我们以安装 CentOS 7 为例:
docker pull centos:centos7
3. 查看本地镜像
使用以下命令查看是否已安装了 CentOS 7:
docker images
镜像信息
在输出中可以看到:
- REPOSITORY:显示为 centos
- TAG:显示为 centos7
- IMAGE ID:镜像的唯一标识
- CREATED:创建时间
- SIZE:镜像大小
4. 运行容器
使用以下命令创建并启动 CentOS 容器:
docker run -itd --name centos-test centos:centos7
参数说明
-i
:交互式操作-t
:终端-d
:后台运行--name
:指定容器名称
进入容器
使用以下命令进入运行中的容器:
docker exec -it centos-test /bin/bash
5. 验证安装
使用以下命令查看容器的运行信息:
docker ps
常用操作
在容器中可以执行以下操作:
# 更新包索引
yum update
# 安装软件包
yum install package-name
# 查看系统信息
cat /etc/centos-release
# 退出容器
exit