What you’ll learn
In this reference, you’ll find:- Commands for building and managing Docker images.
- Commands for running and controlling containers.
- Commands for working with volumes and networks.
- Common command workflows for development and deployment.
- Runpod-specific guidance for container deployment.
Building images
These commands help you create and manage Docker images.docker build
Builds a Docker image from a Dockerfile. This is how you create custom images with your application code and dependencies.-t, --tag: Name and optionally tag the image inname:tagformat.-f, --file: Specify a Dockerfile (default is./Dockerfile).--platform: Set target platform for the build (uselinux/amd64for Runpod).--no-cache: Build without using cache from previous builds.--build-arg: Set build-time variables defined in the Dockerfile.
For Runpod deployments: Always use
--platform=linux/amd64 when building on Apple Silicon Macs or ARM systems. Runpod’s infrastructure requires AMD64 (x86_64) architecture images.docker images
Lists Docker images available on your local system.docker tag
Creates a new tag for an existing image, useful for versioning or preparing images for registry pushes.docker rmi
Removes Docker images from your local system. Useful for cleaning up unused images and freeing disk space.-f).
Managing images in registries
These commands help you share images via Docker registries.docker login
Authenticates with a Docker registry to push or pull private images.docker push
Uploads a Docker image to a registry, making it available for deployment.- Serverless: After pushing your image, specify the image name when deploying your worker. Runpod pulls the image when creating workers.
- Pods: Reference your registry image when choosing a Pod template or creating a custom template.
docker pull
Downloads a Docker image from a registry to your local system.latest tag by default. Be aware that latest doesn’t necessarily mean the most recent version—it’s just a tag name that image maintainers choose to use or not.
Running containers
These commands create and manage running containers.docker run
Creates and starts a new container from an image. This is the most commonly used Docker command.-d, --detach: Run container in background.-p, --publish: Map host port to container port (host:container).-v, --volume: Mount a volume (host_path:container_path).-e, --env: Set environment variables.--name: Assign a name to the container.-it: Interactive mode with terminal (for shells).--rm: Automatically remove container when it exits.--gpus all: Enable GPU access (relevant for Runpod Pods).
docker ps
Lists running containers. Use this to check container status and get container IDs.docker stop, docker logs, or docker exec.
docker stop
Gracefully stops a running container by sending a SIGTERM signal, then SIGKILL if it doesn’t stop within a timeout.docker rm.
docker start
Starts a stopped container. Unlikedocker run, this restarts an existing container rather than creating a new one.
docker restart
Stops and then starts a container. Useful for applying configuration changes or resolving issues.docker rm
Removes stopped containers from your system.Debugging containers
These commands help you inspect and troubleshoot running containers.docker logs
Shows the stdout and stderr output from a container. Essential for debugging and monitoring.docker logs helps debug containers you’re running during development.
docker exec
Executes a command in a running container. Extremely useful for debugging and inspecting container state.docker inspect
Returns detailed low-level information about containers or images in JSON format.Volumes
These commands manage persistent storage for containers.docker volume create
Creates a named volume that can persist data beyond container lifecycles.docker volume ls
Lists all volumes on your system.docker volume rm
Removes a volume. The volume must not be in use by any containers.When working with Runpod, see how to attach network volumes to persist data across Serverless workers or Pod instances. Network volumes provide persistent storage that survives container restarts and can be accessed by multiple workers or Pods.
Networks
These commands manage Docker networks for container communication.docker network create
Creates a custom network that allows containers to communicate with each other.docker network connect
Connects a container to a network.Common workflows
Here are typical command sequences for common tasks.Build, tag, and push a custom image
Develop with live code reloading
Clean up unused resources
Debug a failing container
Learning more
This reference covers the most essential Docker commands. For comprehensive documentation on all Docker CLI commands, see:Next steps
Now that you’re familiar with Docker commands, explore:- Persisting data with volumes for machine learning workflows.
- Serverless worker deployment to run your containers on Runpod.
- Creating Dockerfiles for Serverless with Runpod-specific best practices.
- Pods overview to run long-running GPU containers.