GPU Cloud Server

Install TensorFlow using Docker and configure GPU/CPU support

2026-01-27 09:47:28

You can quickly run TensorFlow on a GPU instance with Docker, only if the instance has the NVIDIA driver installed, and no NVIDIA CUDA toolkit is required.

Before You Begin

· The GPU driver is already installed to the GPU cloud server.

· The operation procedure in this topic takes the CentOS operating system as an example.

Procedure

1. Install Docker

a. Before installing a new Docker version, please uninstall all older versions and associated dependencies.

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine


b. Set the Docker repository.

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

c. Install the Docker engine.

sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

d. Start Docker.

sudo systemctl start docker

2. Install TensorFlow

a. Set the NVIDIA container toolkit

· Set the repository and GPG key.

distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
   && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.repo | sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo

· Install the nvidia-container-toolkit package (and dependencies) after you update the package list.

sudo yum clean expire-cache
sudo yum install -y nvidia-container-toolkit


· Configure the Docker daemon to recognize the NVIDIA container runtime.

sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

· Test the working setup by running the basic CUDA container.

sudo docker run --rm --runtime=nvidia --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi

b. Download the TensorFlow Docker image

The official TensorFlow Docker image is located in the tensorflow/tensorflow Docker Hub codebase. Image versions are tagged in the following format:

Tag

Description

latest

The label contains the latest release (excluding pre-release versions such as release candidate, alpha, and beta)

nightly

Comes with the latest TensorFlow nightly Python package

version

Specifies the version of the TensorFlow binary image, for example 2.13.0

devel

The label is no longer supported. Please use TensorFlow SIG Build Dockerfiles instead

custom-op

The label is no longer supported. Please use TensorFlow SIG Build Dockerfiles instead

Each basic tag has variants with features added or changed:

Tag Variant

Description

tag-gpu

The label is based on Nvidia CUDA. You need nvidia-docker to run them

tag-jupyter

The tag includes Jupyter and some TensorFlow tutorial notebooks

You can in use multiple variants at a time. For example, you can run the following command to download the TensorFlow version image to your computer.

docker pull tensorflow/tensorflow                         # latest stable release
docker pull tensorflow/tensorflow:nightly-gpu            # nightly release w/ GPU support
docker pull tensorflow/tensorflow:latest-gpu-jupyter     # latest release w/ GPU support and Jupyter

c. Start the TensorFlow Docker container

To start the container with TensorFlow configured, use the following command format. For more information, see Docker run reference.

docker run [-it] [--rm] [-p hostPort:containerPort] tensorflow/tensorflow[:tag] [command]

Example

1. Example of images supporting CPU only

Verify the TensorFlow installation effect with the image tagged latest, as shown below. Docker downloads a new TensorFlow image on the first run:

docker run -it --rm tensorflow/tensorflow python

Examples of other TensorFlow Docker schemes are as follows:

· Start a bash shell session in a container with TensorFlow configured:

docker run -it tensorflow/tensorflow bash

· To run the TensorFlow program developed on the server in the container, load the server directory and change the working directory of the container by using the-v hostDir:containerDir -w workDir parameter. Example:

docker run -it --rm -v $PWD:/tmp -w /tmp tensorflow/tensorflow python ./script.py

· Start the Jupyter notebook server using nightly TensorFlow:

docker run -it -p 8888:8888 tensorflow/tensorflow:nightly-jupyter

Please refer to instructions in the Jupyter official website and visit http://127.0.0.1:8888/?token=... with your browser.

2. Example of images supporting GPU

a. Run the following command to download and run the TensorFlow image supporting GPU, and start the image using the Python interpreter.

docker run -it --rm --runtime=nvidia tensorflow/tensorflow:latest-gpu python

b. It may take some time to configure an image supporting GPU. If you run GPU-based scripts repeatedly, you can reuse containers by using docker exec. Run the following command to start a bash shell session in the container using the latest TensorFlow GPU image:

docker run --gpus all -it tensorflow/tensorflow:latest-gpu bash


b1spQ2mtgkp.