Installing Docker on CentOS 7 / RHEL 7

本文介绍如何在CentOS 7上安装Docker,包括从官方源和基础源安装的方法,并解决了一些常见问题。

Docker is a container virtualization technology that has gained widespread popularity in recent times; it offers a more efficient way to deploy the application. With Docker, the applications reside inside the container on top of the Linux operating system. Docker uses Kernel features such as cgroups and namespace to allow an independent container to run on single os instance.

In this post, you will learn how to install Docker on CentOS 7 / RHEL 7

Docker runs only on 64-bit operating system.

Installing Docker:

Choose any one of the methods to install Docker on CentOS 7.

Install from Docker (Official):

Docker is now available in two editions,

  • Community Edition (CE)
  • Enterprise Edition (EE)

Here, we will install Docker Comunity Edition (CE).

Uninstall older versions of Dockers, named “docker” or “docker-engine” along with associated dependencies.

# yum  -y remove  docker-common docker container-selinux docker-selinux docker-engine

Do not worry about the contents inside /var/lib/docker/, all will be preserved.

The Docker Comunity package is now called “docker-ce“. Let’s add the CE repository for docker installation.

# yum -y install  wget
# wget https://download.docker.com/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

Install the latest version of Docker CE using the following command.

# yum -y install docker-ce
Sometime you may want to install particular version of Docker, you do that by appending version like docker-ce-[version]
Eg: yum install docker-ce-17.03.0.ce-1.el7.centos

Install from Base Repository:

Docker is available in the standard repository of CentOS, so we don’t have to search for the package. For RHEL 7, you must have a valid Redhat subscription to enable Extras rpm’s repository on the server. Install it using the following command.

# yum -y install docker

Working with Docker:

Now you have Docker installed onto your machine, start the Docker service in case if it is not started automatically after the installation

# systemctl start docker.service

# systemctl enable docker.service

Troubleshoot:

While starting Docker on CentOS 7, I got a below error.

Apr 18 01:21:00 server docker: /usr/bin/docker: relocation error: /usr/bin/docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference

I solved this by installing following packages on CentOS 7.

# yum -y install device-mapper device-mapper-event device-mapper-libs device-mapper-event-libs

Credit: Stackoverflow

Restart Docker service on CentOS 7.

# systemctl restart docker.service

Once the service is started, verify your installation by running the following command.

# docker run -it centos echo Hello-World

Let’s see what happens when we run “docker run” command. Docker starts a container with centos base image since we are running this centos container for the first time, the output will look like below.

Unable to find image 'centos:latest' locally
Trying to pull repository docker.io/centos ...
0114405f9ff1: Download complete
511136ea3c5a: Download complete
b6718650e87e: Download complete
3d3c8202a574: Download complete
Status: Downloaded newer image for docker.io/centos:latest
Hello-World

Docker looks for centos image locally, and it is not found, it starts downloading the centos image from Docker registry. Once the image has been downloaded, it will start the container and echo the command “Hello-World” in the console which you can see at the end of the output.

Allowing Non-root access:

As you can see in my command, for CentOS, I had to run Docker as a root user. To avoid this, you can follow below procedure to allow non-root users to run Docker containers.

Create a group called docker if it does not exist, run the following commands with root privileges.

# groupadd docker

Add a user that is to be a part of docker group, replace “raj” with your own username.

# useradd raj

Add a user to docker group.

# usermod -aG docker raj

Now you can run a Docker with a non-root user.

FirewallD:

FirwallD in CentOS 7 can conflict with Docker; it is recommended to disable the service.

# systemctl stop firewalld.service
# systemctl disable firewalld.servic

When firewalld is started or restarted it will remove the DOCKER chain from iptables, it prevents Docker from working properly.

If you still want to use Systemd, firewalld is must be started before Docker service. In case if you start or restart firewalld after Docker, you will have to restart the Docker daemon.

That’s All!, You can now start working with Docker.




from:  http://www.itzgeek.com/how-tos/linux/centos-how-tos/installing-docker-on-centos-7-rhel-7-fedora-21.html

### CentOS 7 离线安装 NVIDIA 驱动教程 在 CentOS 7 系统上离线安装 NVIDIA 驱动可以通过以下方法实现。以下是详细的步骤和注意事项: #### 方法一:通过 CUDA 工具包安装 NVIDIA 驱动 当安装 CUDA 工具包时,NVIDIA 驱动会自动安装。以下是具体操作步骤: 1. 下载 CUDA 工具包的本地安装程序。可以从 NVIDIA 官方网站获取对应的版本[^3]。 2. 使用以下命令安装 CUDA 工具包及其驱动: ```bash sudo rpm -Uvh cuda-repo-rhel7-<version>.x86_64.rpm ``` 其中 `<version>` 是具体的 CUDA 版本号。 3. 安装完成后,系统会自动完成 NVIDIA 显卡驱动的安装,并显示类似以下控制台信息: ``` Installing the NVIDIA display driver... Installing the CUDA Toolkit in /usr/local/cuda-9.1 ... ``` 这表明驱动已成功安装[^1]。 #### 方法二:直接下载并安装 NVIDIA 驱动 RPM 包 如果仅需要安装 NVIDIA 驱动而无需 CUDA 工具包,可以按照以下步骤操作: 1. 访问 NVIDIA 官方驱动下载页面[^2],选择适合的驱动版本进行下载。例如: ``` http://www.nvidia.cn/Download/index.aspx?lang=cn ``` 2. 下载对应的 RPM 包,如 `nvidia-diag-driver-local-repo-rhel7-390.30-1.0-1.x86_64.rpm`。 3. 将 RPM 包拷贝到目标机器上,并执行以下命令进行安装: ```bash sudo rpm -Uvh nvidia-diag-driver-local-repo-rhel7-<version>.x86_64.rpm ``` 其中 `<version>` 是具体的驱动版本号。 4. 安装完成后,可以使用以下命令验证驱动是否正常工作: ```bash nvidia-smi ``` 如果命令返回显卡相关信息,则说明驱动安装成功[^2]。 #### 方法三:通过 YUM 源安装驱动 对于内网环境中有多台 GPU 服务器的情况,可以将驱动 RPM 包上传至局域网 YUM 源,以简化安装过程[^5]: 1. 下载 NVIDIA 提供的驱动 RPM 包: ```bash wget http://developer.download.nvidia.com/compute/cuda/11.0.1/local_installers/cuda-repo-rhel7-11-0-local-11.0.1_450.36.06-1.x86_64.rpm ``` 2. 将 RPM 包拷贝到局域网 YUM 源目录,并重新生成索引: ```bash createrepo <yum_source_directory> ``` 3. 在目标机器上配置 YUM 源后,执行以下命令安装驱动: ```bash sudo yum install -y nvidia-driver ``` #### 注意事项 - 确保系统内核版本与 NVIDIA 驱动兼容。不兼容可能导致安装失败或系统无法正常启动[^5]。 - 在安装驱动前,建议停止任何可能占用 GPU 的服务或进程,例如 X 服务器或 Docker 容器[^4]。 - 如果需要同时安装 cuDNN,需从 NVIDIA 开发者网站下载对应版本并解压到指定路径。 ```python # 示例代码:验证 NVIDIA 驱动是否安装成功 import os os.system("nvidia-smi") ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值