Deep Learning

Docker Cheat Sheet for Deep Learning: The Basics

March 27, 2021
7 min read
docker-cheat-sheet.jpg

Docker Cheat Sheet for Deep Learning 

In our previous Docker related blog: "Is Docker Ideal for Running TensorFlow? Let’s Measure Performance with the RTX 2080 Ti" we explored the benefits and advantages of using Docker for TensorFlow. In this blog, we've decided to create a 'Docker Cheat Sheet' and best practices that have helped us along the way. We welcome you to have a look, keep this blog as a reference, and if you think we left something out or know of a good tip/trick on Docker that's saved you, let us know, and we'll add it to the blog!

Basic Docker Terms You Should Know.

  • Image: Docker images are the foundations of containers. Images are an immutable, ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime.
  • Container: An instance of the image that can be executed as an independent application. The container has a mutable layer that lies on top of the image, dependencies isolated from the host machine.
  • Volume: A volume is a specially-designated directory within one or more containers that bypasses the Union File System. Volumes are designed to persist data, independent of the container’s life cycle.
  • Registry: A storage and content delivery system used for distributing Docker images.
  • Repository: A collection of related Docker images, often different versions of the same application.

Note: There are more terms you may want to pick up on, check the glossary at the Docker website.

Launching Your Deep Learning Environment in Docker

Let's take a look at some common Docker syntax by running a practical example. We'll break it down piece by piece. Assuming your dependencies are installed, (or you're using an Exxact deep learning workstation or server) you can fire up a TensorFlow container by entering the following command in a terminal:

docker run --gpus all -it -p 8888:8888 -p 6006:6006 -v ~/mywork:/benchmarks tensorflow/tensorflow:nightly-gpu bash


Breaking Down the Above Docker Command

Docker SyntaxDescription
docker run --gpus allThe 'docker run' command specifies the IMAGE to derive the container from. Note in this case we use 'docker run' to utilize CUDA powered NVIDIA GPUs. GPU devices to add to the container ('all' to pass all GPUs).
-itThis parameter creates an interactive terminal you can use to interact with your container
-p 8888:8888 Expose port 8888:8888 [HOST:CONTAINER] for Jupyter notebook, effectively maps the container port to the host port using localhost interface (type localhost:8888 in your browser).
-p 6006:6006Expose port 6006:6006 [HOST:CONTAINER] for Tensorboard, maps the container port to the host port using localhost interface (type localhost:6006 in your browser).
-v ~/mywork:/benchmarksVolume tag, This shares the folder ~/mywork on your host machine to /benchmarks folder inside your container. In generic terms -v /[host folder]:/[container folder]
tensorflow/tensorflow:nightly-gpuThis the image that you want to run. The Docker Hub format is [PUBLISHER]/[IMAGE REPO]:[IMAGE TAG] In our case, we use the image 'tensorflow' with 'nightly-gpu' image tag (if we didnt specify a image tag, the default tensorflow image will be used).
bashThis will create a new Bash session in the container.

Quick Tip: Starting a Stopped/Exited Container

1. Start the Container

docker start [container name or ID]

2. Start an interactive bash within the container

docker exec -it [container name or ID] bash

NVIDIA-DEEP-LEARNING-SERVERS-WORKSTATIONS.png

Working With Docker Containers

CommandOPTIONSExplanation

docker container ls [OPTIONS]

-aShow all containers (default shows just running)
-fFilter output based on conditions provided
--formatPretty-print containers using a Go template
--last, -nShow n last created containers (includes all states)
-sDisplay total file sizes

Docker Hub Commands

CommandDescription

docker pull [image name]

Downloads image from Docker Hub.

docker search [keyword]

Search Docker Hub for images.

docker push [user/imagename]

Uploads an image to Docker Hub.

docker login [options] [server]

Login to Docker Hub

Image and Container Information

CommandDescription
docker container lsList all running containers.
docker container ls -aList all containers running or stopped
docker image lslist images
docker volume lslist volume
docker logs [container name or ID]Displays the logs from a running container.
docker port [container name or ID]View a list of the ports defined on a container.

Other useful commands when working with Docker images and containers

Docker CommandDescription

docker run --gpus all -it user/image

Run an image, create a container and change the current terminal to a terminal within the container.
docker run --gpus all -p [HOSTPORT:CONTAINERPORT] -d user/imageRun an image in detached mode with port forwarding [HOSTPORT:CONTAINERPORT] .
docker attach [container name or ID]Change the command prompt from host to running container.
docker start [container name or ID]Start a container.
docker stop [container name or ID]Stop a container.
docker rm [container name or ID]Remove a container.
docker rmi [image name or ID]Delete an image.
docker tag user/image:tag user/image:newtagAdd new tag to an image.
docker exec [container name or ID] shell commandExecute a command within a running container.

That's it for now, we've only touched on a few Docker tips and commands that have helped us. What Docker commands do you feel we should have included in this Docker Cheat Sheet? Let us know!

eBook-DL-1024x202.jpg

Topics

docker-cheat-sheet.jpg
Deep Learning

Docker Cheat Sheet for Deep Learning: The Basics

March 27, 20217 min read

Docker Cheat Sheet for Deep Learning 

In our previous Docker related blog: "Is Docker Ideal for Running TensorFlow? Let’s Measure Performance with the RTX 2080 Ti" we explored the benefits and advantages of using Docker for TensorFlow. In this blog, we've decided to create a 'Docker Cheat Sheet' and best practices that have helped us along the way. We welcome you to have a look, keep this blog as a reference, and if you think we left something out or know of a good tip/trick on Docker that's saved you, let us know, and we'll add it to the blog!

Basic Docker Terms You Should Know.

  • Image: Docker images are the foundations of containers. Images are an immutable, ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime.
  • Container: An instance of the image that can be executed as an independent application. The container has a mutable layer that lies on top of the image, dependencies isolated from the host machine.
  • Volume: A volume is a specially-designated directory within one or more containers that bypasses the Union File System. Volumes are designed to persist data, independent of the container’s life cycle.
  • Registry: A storage and content delivery system used for distributing Docker images.
  • Repository: A collection of related Docker images, often different versions of the same application.

Note: There are more terms you may want to pick up on, check the glossary at the Docker website.

Launching Your Deep Learning Environment in Docker

Let's take a look at some common Docker syntax by running a practical example. We'll break it down piece by piece. Assuming your dependencies are installed, (or you're using an Exxact deep learning workstation or server) you can fire up a TensorFlow container by entering the following command in a terminal:

docker run --gpus all -it -p 8888:8888 -p 6006:6006 -v ~/mywork:/benchmarks tensorflow/tensorflow:nightly-gpu bash


Breaking Down the Above Docker Command

Docker SyntaxDescription
docker run --gpus allThe 'docker run' command specifies the IMAGE to derive the container from. Note in this case we use 'docker run' to utilize CUDA powered NVIDIA GPUs. GPU devices to add to the container ('all' to pass all GPUs).
-itThis parameter creates an interactive terminal you can use to interact with your container
-p 8888:8888 Expose port 8888:8888 [HOST:CONTAINER] for Jupyter notebook, effectively maps the container port to the host port using localhost interface (type localhost:8888 in your browser).
-p 6006:6006Expose port 6006:6006 [HOST:CONTAINER] for Tensorboard, maps the container port to the host port using localhost interface (type localhost:6006 in your browser).
-v ~/mywork:/benchmarksVolume tag, This shares the folder ~/mywork on your host machine to /benchmarks folder inside your container. In generic terms -v /[host folder]:/[container folder]
tensorflow/tensorflow:nightly-gpuThis the image that you want to run. The Docker Hub format is [PUBLISHER]/[IMAGE REPO]:[IMAGE TAG] In our case, we use the image 'tensorflow' with 'nightly-gpu' image tag (if we didnt specify a image tag, the default tensorflow image will be used).
bashThis will create a new Bash session in the container.

Quick Tip: Starting a Stopped/Exited Container

1. Start the Container

docker start [container name or ID]

2. Start an interactive bash within the container

docker exec -it [container name or ID] bash

NVIDIA-DEEP-LEARNING-SERVERS-WORKSTATIONS.png

Working With Docker Containers

CommandOPTIONSExplanation

docker container ls [OPTIONS]

-aShow all containers (default shows just running)
-fFilter output based on conditions provided
--formatPretty-print containers using a Go template
--last, -nShow n last created containers (includes all states)
-sDisplay total file sizes

Docker Hub Commands

CommandDescription

docker pull [image name]

Downloads image from Docker Hub.

docker search [keyword]

Search Docker Hub for images.

docker push [user/imagename]

Uploads an image to Docker Hub.

docker login [options] [server]

Login to Docker Hub

Image and Container Information

CommandDescription
docker container lsList all running containers.
docker container ls -aList all containers running or stopped
docker image lslist images
docker volume lslist volume
docker logs [container name or ID]Displays the logs from a running container.
docker port [container name or ID]View a list of the ports defined on a container.

Other useful commands when working with Docker images and containers

Docker CommandDescription

docker run --gpus all -it user/image

Run an image, create a container and change the current terminal to a terminal within the container.
docker run --gpus all -p [HOSTPORT:CONTAINERPORT] -d user/imageRun an image in detached mode with port forwarding [HOSTPORT:CONTAINERPORT] .
docker attach [container name or ID]Change the command prompt from host to running container.
docker start [container name or ID]Start a container.
docker stop [container name or ID]Stop a container.
docker rm [container name or ID]Remove a container.
docker rmi [image name or ID]Delete an image.
docker tag user/image:tag user/image:newtagAdd new tag to an image.
docker exec [container name or ID] shell commandExecute a command within a running container.

That's it for now, we've only touched on a few Docker tips and commands that have helped us. What Docker commands do you feel we should have included in this Docker Cheat Sheet? Let us know!

eBook-DL-1024x202.jpg

Topics