Title: Getting Used to Docker for Machine Learning - PyImageSearch

URL Source: https://pyimagesearch.com/2023/10/09/getting-used-to-docker-for-machine-learning/

Published Time: 2023-10-09T13:00:00+00:00

Markdown Content:
* * *

**Table of Contents**
---------------------

*   [Getting Used to Docker for Machine Learning](#h2BPTitle)

*   [Introduction](#h3Introduction)
*   [A Quick Recap](#h3Recap)
*   [Dockerfile > Docker Image > Docker Container](#h3Dockerfile)

*   [Dockerfile](#h4Dockerfile)
*   [Docker Image](#h4Image)
*   [Docker Container](#h4Container)

*   [Example: Deploying a Flask API Container from Scratch](#h3Scratch)

*   [Python Code for Flask API to Sum 2 Numbers](#h4Sum)
*   [Breaking Down the Dockerfile, Step by Step](#h4Breaking)
*   [Building an Image from the Dockerfile](#h4Building)
*   [Creating a Container with the Docker Image](#h4Creating)
*   [Testing the Container](#h4Test)

*   [Common Docker Commands](#h3Common)

*   [`docker ps`](#h4ps)
*   [`docker build`](#h4build)
*   [`docker start`](#h4start)
*   [`docker stop`](#h4stop)
*   [`docker push`](#h4push)
*   [`docker pull`](#h4pull)
*   [`docker login`](#h4login)
*   [`docker run`](#h4run)
*   [`docker exec`](#h4exec)
*   [`docker attach`](#h4attach)
*   [`docker kill`](#h4kill)
*   [`docker commit`](#h4commit)
*   [`docker rm`](#h4rm)
*   [`docker rmi`](#h4rmi)
*   [`docker search`](#h4search)
*   [`docker restart`](#h4restart)
*   [`docker rename`](#h4rename)

*   [Summary](#h2Summary)

*   [Citation Information](#h3Citation)

* * *

In this tutorial, you will learn about Docker containers for machine learning, how to make a Docker container, how to work with the Docker CLI (command line interface), and much more.

[![Image 1](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20603%20500'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2023/10/docker-2-featured.png)

This lesson is the 2nd of a 3-part series on **Docker for Machine Learning**:

1.  [_Getting Started with Docker for Machine Learning_](https://pyimg.co/k3xw6)
2.  [**_Getting Used to Docker for Machine Learning_**](https://pyimg.co/hf5bk) **(this tutorial)**
3.  _Lesson 3_

**To learn how to create a Docker Container for Machine Learning, _just keep reading._**

* * *

[**Getting Used to Docker for Machine Learning**](#TOC-h2BPTitle)
-----------------------------------------------------------------

* * *

### [**Introduction**](#TOC-h3Introduction)

Docker is a powerful addition to any development environment, and this especially rings true for ML Engineers or enthusiasts who want to get started with experimentation without having to go through the hassle of setting up several drivers, packages, and more.

In today’s blog, we will look at how we can **create and build our own containers with a Dockerfile**, followed by the **most commonly used Docker commands** and the concepts behind them.

In short, we will see how we can leverage them to _supercharge_ our development experience.

Let’s get started!

* * *

### [**A Quick Recap**](#TOC-h3Recap)

In the [previous blog post of this series](https://pyimg.co/k3xw6), we saw what containers are, what Docker is supposed to do, and how to set up the NVIDIA Container Toolkit to leverage NVIDIA containers for our workflow.

Containers are **simple all-in-one packages** that encapsulate everything you need to set up an environment, including files, dependencies, drivers, and more.

You can use Docker to create, handle, manipulate, and run containers on your system locally. It can also be used on **Cloud-based providers** (e.g., [**AWS**](https://aws.amazon.com/)**,** [**GCP**](https://console.cloud.google.com/)**,** [**Azure**](https://azure.microsoft.com/en-in)**,** [**DigitalOcean**](https://www.digitalocean.com/), etc.) to set up containerized workflows.

With the NVIDIA Container Toolkit, you can use containers to simplify driver setup and experiment rapidly on any hardware, whether on your local machine or the cloud.

* * *

### [**Dockerfile > Docker Image > Docker Container**](#TOC-h3Dockerfile)

[![Image 2](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20302'%3E%3C/svg%3E)](https://lh3.googleusercontent.com/jr7f9KZSn7PInZeWwYdIU9KW52FxEgCsjp4GFy49Fub3UUsTjVMzdYSHK2SMIzzs8AeNm_46Ruj-a2nKo27KSs56ONQ3MMRZUWA8TAEDJG0tzBkeZzd7ZgtSbUsXgzN0cw2674apyFsVO3ix8EA13a8)

We begin by taking a look at the Dockerfile. What is a Dockerfile, and what should we do with it?

* * *

#### [**Dockerfile**](#TOC-h4Dockerfile)

A Dockerfile can be considered a **manifest, or a listed sequence of steps** the Docker engine will take to **recreate your desired environment**. This would include steps related to downloading certain components, performing some commands, and anything that you would do on a simple command line to configure everything from scratch.

This manifest becomes the base on which you develop the next artifact in the chain (i.e., the image).

* * *

#### [**Docker Image**](#TOC-h4Image)

A Docker Image is the **reproducible template that is created when you build the Dockerfile**. Images tend to contain everything needed to run the environment. That includes the code, packages, drivers, system tools, etc. They are meant to be **immutable**, meaning an image will reflect the exact sequence and setup of the original Dockerfile. Another important thing to note is that images tend to have a layered filesystem, meaning you can make an image on top of other images. Images allow you to create multiple containers based on the same structure.

* * *

#### [**Docker Container**](#TOC-h4Container)

A Docker Container is an **encapsulated runtime that gives you all packages, code, system libraries, and runtime tools in a single place**. They are built on top of the Docker image and run the defined application. Often, containers are used as self-sufficient packages that can be made to work independently. An example of such a case would be deploying a simple Flask Web API (application programming interface), which would keep running in perpetuity (or until the container is shut down).

Now that we know what each component does, let’s start trying to build them from scratch with a random toy example. We will create a Dockerfile for an API that returns the sum of 2 numbers, create a Docker image for it, and run a container from that image. Let’s get started!

* * *

### [**Example: Deploying a Flask API Container from Scratch**](#TOC-h3Scratch)

First, let’s get our API ready. This should be a fairly quick and straightforward task with the help of Flask! It allows us to start API development within a few lines of simple Python code.

* * *

#### [**Python Code for Flask API to Sum 2 Numbers**](#TOC-h4Sum)

\`\`\`python
from flask import Flask, request

app = Flask(\_\_name\_\_)

@app.route('/add', methods=\['POST'\])
def add():
    numbers = request.get\_json()
    number1 = numbers\['number1'\]
    number2 = numbers\['number2'\]
    result = number1 + number2
    return {'result': result}

if \_\_name\_\_ == '\_\_main\_\_':
    app.run(host='0.0.0.0', port=8000)
\`\`\`

With that, we now have a boilerplate API ready to deploy. This piece of code allows us to deploy an API that listens on port 8000 for requests with 2 numbers as JSON arguments, sums them up, and returns them as a result.

Let’s look at the Dockerfile now and go line by line.

* * *

#### [**Breaking Down the Dockerfile, Step by Step**](#TOC-h4Breaking)

\`\`\`Dockerfile
FROM python:3.10

Using the **`FROM` command allows you to specify a template pre-existing Docker Image you would like to build your own image on top of**. There are thousands of pre-existing images, with several being from official repository maintainers. For example, containers exist to configure NGINX, Redis, and many other popular tools. A common way to prototype with Python containers is to simply build on top of official Python images, available for several different versions.

RUN pip install flask

The **`RUN` command, allows you to run a shell command as part of the setup**. This is useful in interacting with shell utilities and executing scripts. Here, we use it to install Flask as our only dependency. If you have more dependencies warranting the use of a `requirements.txt` file, you can use that with the help of the `pip install -r requirements.txt` command appended to `RUN`.

WORKDIR /app

**`WORKDIR` tells Docker the directory that would be considered the main working directory for the application**. This is where the shell would start and be available for use. It will create a new directory named `/app` as specified.

COPY app.py /app/app.py

**`COPY` allows us to move files and directories from our local device into the image’s file structure**. The container will have a parallel file structure from the local device, meaning we must copy the files to access them within the container.

EXPOSE 8000/tcp

**`EXPOSE` allows us to tell Docker that the container will listen to a certain port while it is running**. This can be useful for controlling networking operations, allowing us to specify the protocol (TCP/UDP). For our purposes, we’ll stick to simple TCP.

ENTRYPOINT \[ "python", "app.py" \]

**`ENTRYPOINT` allows us to define a command that will trigger an executable within the container**. It also is meant to make the container behave as an executable. This command often starts an application to follow an event-driven loop that listens to incoming traffic. We use it to start our Flask API, which will now listen on Port 8000 for TCP traffic and return a result when the right parameters are passed in the right format.

* * *

#### [**Building an Image from the Dockerfile**](#TOC-h4Building)

Now, let’s look at building the container. We use the Docker CLI (command line interface) to do so. Navigate to your local working directory and use the following command.

\`\`\`shell
docker build . -t <your-dockerhub-username>/docker-trial-pyimagesearch
\`\`\`

In this command, we executed the building operation. This will use the Dockerfile and generate an image. Additionally, the `-t` (or `--tag`) flag is used to give a nametag to your image.

* * *

#### [**Creating a Container with the Docker Image**](#TOC-h4Creating)

Once the process to build is complete, your image is ready to use. Enter the command below to fire up a single container based on that image. We’ll look into this command in detail, too.

\`\`\`shell
docker run -p 8050:8000 <your-dockerhub-username>/docker-trial-pyimagesearch
\`\`\`

This command will now create a single container with the image you specified. The flag `-p` (or `--publish`) performs port forwarding. It binds a port of the local machine to a specified port of the container, so all traffic for those ports is routed accordingly. There is no compulsion to have the same ports routed (i.e., you can have a map of type 8050:8000 where port 8000 of the container will bind to port 8050 of the local machine).

* * *

#### [**Testing the Container**](#TOC-h4Test)

With the container now up and running, let’s test a sample request with cURL (Client for URL). Feel free to use the `cURL` command below.

\`\`\`cURL Request
curl -X POST 
    -H "Accept: application/json" 
    -H "Content-Type: application/json" 
    'http://127.0.0.1:8000/add' -d '{"number1":10, "number2":20}'
\`\`\`

In this command, we pass 2 headers indicating that we will send JSON data in the request and finally use the `-d` flag to pass the parameters. Note how the URL uses the localhost URL, while the actual application runs on the container!

So that’s it! We just went from having a simple Python Flask API on hand to making it a Docker image to be easily deployed. It can be replicated as much as we would like!

* * *

### [**Common Docker Commands**](#TOC-h3Common)

Now, let’s look at some common commands for use in Docker so that you can get around the entire ecosystem well. The commands below will allow you to interact with your containers, manipulate them to your requirements, and execute content within them. Let’s get started!

* * *

#### [**`docker ps`**](#TOC-h4ps)

This command returns a list of containers that are currently active and running. It returns information about the Container ID and the base Image for the container.

**Example:** `docker ps`

**Example output:**

[![Image 3](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh4.googleusercontent.com/c2ayEYcEqAzI4sTUo0h8ZfFZB24WwZ8oIr1dkkevbW6yqJaFySnxWtZxrt5y7EwaDawSvcv0nWD9Z4gL-uITfHPngx1b-pG0mfcUXQzzm8fDoRmgy4IwQzEWOVo7le2as_zTfuChdxx_RdVkD_9A5lk)

* * *

#### [**`docker build`**](#TOC-h4build)

This command is used to start building your container from the Dockerfile present in your filesystem structure. Using the `-t` flag allows you to tag your build with a name that can be used to reference it later.

**Example:** `docker build . -t suvadityamuk/docker-trial-pyimagesearch`

**Example output:**

[![Image 4](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20434'%3E%3C/svg%3E)](https://lh5.googleusercontent.com/v2Ywy6uv7fpXJsha6YaLhyH2pXDevyAxwTWur2RLCY46c-CRAaVEw922Z_yq2Bx9NhAkRijBt4tsKI1dLf9PWma3t-4BYYb6-TFnAyJX8dw8Gf6jpB0uuA5XrlAJZfDLSOneMRivJZm-JUsMrhFK52Q)

* * *

#### [**`docker start`**](#TOC-h4start)

This command starts up a container that may have been previously shut down or stopped. We pass the container ID as an argument.

**Example:** `docker start f4d`

**Example output:**

[![Image 5](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh5.googleusercontent.com/dSf1_7XFLPNvHEbAThaTEauy3gzundwqvX0eHrmnnPsqLBl_GdVtmyWuLrUDi1PSKx6X78PnjvqjRRiSqv4qlxOH5gR1-RkWyyc-mYGwI6nb613_hvobjLH40zOes6Y2LU-OgaIpoNeE6i6Q9ZFvsRc)

* * *

#### [**`docker stop`**](#TOC-h4stop)

This command shuts down a specific container. For this command, we need the container name or container ID (which can be taken from `docker ps`!)

**Example:** `docker stop f4d`

**Example output:**

[![Image 6](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh3.googleusercontent.com/RNtIgFRDxXwOSQnEpDZQE4ldo7P4hxFcp5Hy7WPG3P-w6lyAUyg3e3nO9cUCoJgdzOV0379QvKZr_nBOAFigz-dRfwxtM1c77vNMGiLVSql5aGKICfanMxpXfE0p13ngNANebagXCDXU9XB7PIm3gtw)

* * *

#### [**`docker push`**](#TOC-h4push)

This command takes the image you created for a certain Dockerfile and pushes it to Docker Hub. This allows you to use this image from anywhere you log in, with Docker.

**Example:** `docker push suvadityamuk/docker-trial-pyimagesearch`

**Example output:**

[![Image 7](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20218'%3E%3C/svg%3E)](https://lh4.googleusercontent.com/hbyAXMRnIAiUmQveXXmVCGDYwr06TeMWBSZbo0xvcuso6uyfYsHrFeEEnwYUuaLla3f9tWCN_V0aiEpnl5DH_SKJ15urEsgsu4XJfD3Nn-StGzWpiLOEt0uXFG_zRP-th7nlMr0sV4547NcM_TqY5Xg)

* * *

#### [**`docker pull`**](#TOC-h4pull)

The inverse of the `docker push` command will allow you to pull any Docker image you may have access to. This enables you to use the image and create containers.

**Example:** `docker pull suvadityamuk/docker-trial-pyimagesearch`

**Example output:**

[![Image 8](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%2091'%3E%3C/svg%3E)](https://lh3.googleusercontent.com/e_dm7m_Hkq16-Gx-3gHd3avc98ApmbAPweJx1DOY0iWxEdwU14d4-GMtgVh8-D5eHW7Vpq6GuFwL52vjGvDO9V_KFB1OrOBE3v785B161vvxrJq-wtzpud5AA2k_yUxl7KeIggMyUTSPXRAt__jg1t8)

* * *

#### [**`docker login`**](#TOC-h4login)

This is a simple command to log into Docker Hub, to allow for push/pull operations. This is very similar to using GitHub with Git on a local machine.

**Example:** `docker login`

**Example output:**

[![Image 9](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh6.googleusercontent.com/ok369hrSsj-rKCdxZSW430hUo6lIeOJjGLk1T4yCA_fyAEhDqNgO0Fuz3kwKHOZqVhHRzf3LhvxJXq7_NhRqIemlXRmHqpDZ8IVR7Z5BwuOdlVCpvula2IthR2driAekYoiNfPIB4trF1yrqZwif3NQ)

* * *

#### [**`docker run`**](#TOC-h4run)

This command creates a new container based on a certain image available locally. This highly configurable command has several options to allow for changes like port-forwarding, attaching/mounting data storage volumes, and more.

*   Using the `-p` or `--publish` flag allows you to bind a port of the container to a certain port on the local machine, such that any traffic to or from the container can be passed through that port on the local machine.
*   Using the `-d` or `--detach` flag allows you to detach the container, such that the container runs in the background while allowing the use of the terminal as usual.
*   Using the `--cpus` flag allows you to pass how many CPU cores you’d like the container to use.
*   Using the `--memory` flag allows you to pass how much memory the container should be able to use.
*   Using the `--gpus` flag allows you to pass which GPUs on the local machine should be available to the container. One can pass the `--gpus all` flag argument for allowing all GPUs. Note that, to make this work, we need the [NVIDIA Container Runtime](https://nvidia.github.io/nvidia-container-runtime/).

**Example:** `docker run -p 8000:8000 -–cpus 1 -–gpus all suvadityamuk/docker-trial-pyimagesearch`

**Example output:**

[![Image 10](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh5.googleusercontent.com/TWkwtplXvNRyewVB96CpDVf9AMn7JNzSx1b4IGprHHrxftaloSwEP426wcHfQHRsZVgHZhtryL03rSzOqG9adQtPOe3sH2VTMNWHodErsk2UXQBpwWUfvyfz2XMJ4ik1eo__TUDHL4BaLuXPF6Qu9Us)

* * *

#### [**`docker exec`**](#TOC-h4exec)

This allows you to execute a certain command on a container. This is useful to open a terminal session inside a container or perform some kind of checks and so on. We must pass the container ID as an argument.

*   The command passed can also be an executable (here, we actually use the `/bin/bash` executable to start a bash shell session).

**Example:** `docker exec -it f412 /bin/bash`

**Example output:**

[![Image 11](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%2057'%3E%3C/svg%3E)](https://lh3.googleusercontent.com/FUHoE7vvkK9pmGyt4i7N6E-8Y1rlizoZYu9T4E5Aa2CQMyynT5PeziYDuKPFS4rzcX_s-msa-aFNTwEUdmpPcKYFHClF_1od-libRXL7WecM7oOYjSfj1wD9UGSsJUjClc6ItYsVmiewJyGLW5IQUDQ)

* * *

#### [**`docker attach`**](#TOC-h4attach)

This lets us connect the container’s internal bash terminal directly with our current local machine’s terminal session. Any commands executed in this environment are executed within the container.

**Example:** `docker attach f412`

* * *

#### [**`docker kill`**](#TOC-h4kill)

This command allows us to kill a container’s internal process. The container is sent a SIGKILL signal, which normally tends to terminate the container itself.

**Example:** `docker kill ae86`

**Example output:**

[![Image 12](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh6.googleusercontent.com/n-WuFPS2YnhKvgDl8gEZ96DNxx6HzTjacOLukE3NrX8NJdp8kmOTwfNOoUJeXffvl2AfHke4wAEnNFUrWijlIZDIhVbWyGAWIBtitL4jtXkoaCRaS0ub6yh4byIO3I-5ri96h0a5Q3zTBHKdnzbBnMA)

* * *

#### [**`docker commit`**](#TOC-h4commit)

This command is used to commit changes made to a certain image in a git-like fashion. Changes internally made to an image (e.g., moving directories/files) can induce changes that require the image to be built again. If you wish to reflect this new image across Docker Hub, we can commit and push the changes ahead.

*   The changes are reflected in the Dockerfile, so we can only write Dockerfile-compatible statements. In the example below, we create a dummy Environment variable called `test_env` and set its value to `True`. The command returns a SHA hash reflecting the commit hash.

**Example:** `docker commit -c "ENV test_env=true" d470 suvadityamuk/docker-trial-pyimagesearch:latest`

**Example output:**

[![Image 13](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh6.googleusercontent.com/MBCPAAGIlYLJkqezXpKJL-FWcxZdRXjBRVVzhNO7qhN8ig-5KLREqKcdsSK33TpGynVxoIUH8f4OfvR87IBZALm7iIPA0TUZaJCVPWPqPZF-jRjnkFnWoODiYMA0bGGkgHNGHEYvHQGX9grLoK9a8ps)

* * *

#### [**`docker rm`**](#TOC-h4rm)

This command is used to delete a certain container. It is important to ensure that the container is already shut down. If it is not, and you still wish to shut it down, we must use the `-f` flag to force the removal.

**Example:** `docker rm d470`

**Example output:**

[![Image 14](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh5.googleusercontent.com/PU55EXIBsrEBvcccp91IkpiVQE7T9mUv-wgmIPajcQ1un4KtFT7vHtkZaXsp9jvGkEMXNjDaBtY99pv_NMckY2ZqbxD8WrzmC2HOLz6_2JETZGPPMzURaRmRbwTlJ_E999gOrcjH75bxyGVWv9kuHx0)

* * *

#### [**`docker rmi`**](#TOC-h4rmi)

This command is used to delete a certain image from the local machine. Doing this means that we cannot use the image again to create containers until we download or pull it back on. If there are running containers that use the chosen image, we must use the `-f` flag to force removal.

**Example:** `docker rmi suvadityamuk/docker-trial-pyimagesearch`

**Example output:**

[![Image 15](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%2070'%3E%3C/svg%3E)](https://lh6.googleusercontent.com/NpcWA2M-Wu8M0SAbWS6FoFbO4i-3TaTJ2THR7HNl0xJx-IsNmTZFspCD9GD_lytdKoMdmjR80eAio7J1pSZr4Vpuwk6jyqR8qTVZh3ApePlCq04M4yLUkc1762QUKXQagdKuHYZspKDOBJSER7Yy0m4)

* * *

#### [**`docker search`**](#TOC-h4search)

This allows us to search for images on Docker Hub with their names or other specific filters.

**Example:** `docker search python`

**Example output:**

[![Image 16](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20334'%3E%3C/svg%3E)](https://lh4.googleusercontent.com/a3PyIHvkbVCmCoO40rJAPMLPjp7OdJW21uRV6eC7z-VyQIrKn_L5aRW2UpY4nuRZ9FnVT6BlK0Mw07GwVv9OFP8-ebhhEF_usohx_0CkjoE2nYcQYFpijTLZBl_CSqVWPf4X1wJUXnfq3s1YGdfD7HI)

* * *

#### [**`docker restart`**](#TOC-h4restart)

This command stops and restarts a container.

**Example:** `docker restart`

**Example output:**

[![Image 17](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh4.googleusercontent.com/Nc1c4ecU7EL5b8d0Xls3dqFyOtf0cySCEtPDX7nGZiAC0MHJOa_ONVJvKt2q6T4WJCL37XvX03wV5UwY6iTwGjcK0tWgwoGH6gSK17GIp8nj3Q2FXKf35TsSbq1mh7vDsr_JjYT1Yourq6vHhlCUCqE)

* * *

#### [**`docker rename`**](#TOC-h4rename)

This command is used to change the human-readable name of a container.

**Example:** `docker rename 4d8d "my-container"`

**Example output:**

[![Image 18](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh6.googleusercontent.com/968GmRBnXR_gGJiGa329yeUJfwsUe-IrMaw4BnjLY1TvoD8j4WR3wnzXrb-dN2DocSdFWrazBVDZNyxVjbKlgSbNsf5s6mgseINGNJrLnOa_l_5NP_s-9VDA14IgChi8GH__v2ofGWLtcmV_l2DEUmc)

* * *

### What's next? We recommend [PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend).

**Course information:**  
84 total classes • 114+ hours of on-demand code walkthrough videos • Last updated: February 2024  
★★★★★ 4.84 (128 Ratings) • 16,000+ Students Enrolled

**I strongly believe that if you had the right teacher you could _master_ computer vision and deep learning.**

Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?

That’s _not_ the case.

All you need to master computer vision and deep learning is for someone to explain things to you in _simple, intuitive_ terms. _And that’s exactly what I do_. My mission is to change education and how complex Artificial Intelligence topics are taught.

If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to _successfully_ and _confidently_ apply computer vision to your work, research, and projects. Join me in computer vision mastery.

**Inside PyImageSearch University you'll find:**

*   ✓ **84 courses** on essential computer vision, deep learning, and OpenCV topics
*   ✓ **84 Certificates** of Completion
*   ✓ **114+ hours** of on-demand video
*   ✓ **Brand new courses released _regularly_**, ensuring you can keep up with state-of-the-art techniques
*   ✓ **Pre-configured Jupyter Notebooks in Google Colab**
*   ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
*   ✓ Access to **centralized code repos for _all_ 536+ tutorials** on PyImageSearch
*   ✓ **Easy one-click downloads** for code, datasets, pre-trained models, etc.
*   ✓ **Access** on mobile, laptop, desktop, etc.

[Click here to join PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend)

* * *

[**Summary**](#TOC-h2Summary)
-----------------------------

That’s it! In this blog post, we look at the following:

*   What makes a Docker container
*   What are the components and steps to create a Docker container
*   What a sample container for a simple Flask App looks like
*   How we can manipulate containers using the Docker CLI (command line interface)
*   We discuss how containers can be used as self-contained executables

In the next blog post, we will get completely hands-on and see how to set up a full Jupyter environment through Docker on a GPU-enabled machine on a Cloud service.

* * *

### [**Citation Information**](#TOC-h3Citation)

**Mukherjee, S.** “Getting Used to Docker for Machine Learning,” _PyImageSearch_, P. Chugh, A. R. Gosthipaty, S. Huot, K. Kidriavsteva, and R. Raha, eds., 2023, [https://pyimg.co/hf5bk](https://pyimg.co/hf5bk)

@incollection{Mukherjee\_2023\_Docker4ML-P2,
  author = {Suvaditya Mukherjee},
  title = {Getting Used to Docker for Machine Learning},
  booktitle = {PyImageSearch},
  editor = {Puneet Chugh and Aritra Roy Gosthipaty and Susan Huot and Kseniia Kidriavsteva and Ritwik Raha},
  year = {2023},
  url = {https://pyimg.co/hf5bk},
}

* * *

![Image 19: Featured Image](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20500%20276'%3E%3C/svg%3E)

### Unleash the potential of computer vision with Roboflow - Free!

*   Step into the realm of the future by [signing up or logging into your Roboflow account](https://roboflow.com/?ref=pyimagesearch). Unlock a wealth of innovative dataset libraries and revolutionize your computer vision operations.
*   Jumpstart your journey by choosing from our broad array of datasets, or benefit from PyimageSearch’s comprehensive library, crafted to cater to a wide range of requirements.
*   Transfer your data to Roboflow in any of the 40+ compatible formats. Leverage cutting-edge model architectures for training, and deploy seamlessly across diverse platforms, including API, NVIDIA, browser, iOS, and beyond. Integrate our platform effortlessly with your applications or your favorite third-party tools.
*   Equip yourself with the ability to train a potent computer vision model in a mere afternoon. With a few images, you can import data from any source via API, annotate images using our superior cloud-hosted tool, kickstart model training with a single click, and deploy the model via a hosted API endpoint. Tailor your process by opting for a code-centric approach, leveraging our intuitive, cloud-based UI, or combining both to fit your unique needs.
*   Embark on your journey today with absolutely no credit card required. Step into the future with Roboflow.

[Join Roboflow Now](https://roboflow.com/?ref=pyimagesearch)

* * *

**![Image 20](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20410%20567'%3E%3C/svg%3E)

#### Join the PyImageSearch Newsletter and Grab My FREE 17-page Resource Guide PDF

Enter your email address below to **join the PyImageSearch Newsletter** and **download my FREE 17-page Resource Guide PDF** on Computer Vision, OpenCV, and Deep Learning.

**