Skip to main content
This reference guide covers the most commonly used Docker commands for working with images and containers. Use this as a quick reference when building and deploying applications, especially for Runpod’s bring-your-own-container (BYOC) workflows with Serverless and Pods.

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.
Common options:
  • -t, --tag: Name and optionally tag the image in name:tag format.
  • -f, --file: Specify a Dockerfile (default is ./Dockerfile).
  • --platform: Set target platform for the build (use linux/amd64 for 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.
Each image shows its repository, tag, image ID, creation date, and size. Image IDs are useful when you need to reference an untagged image or want to be precise about which image to use.

docker tag

Creates a new tag for an existing image, useful for versioning or preparing images for registry pushes.
Tags don’t create copies of images; they’re just additional names pointing to the same image data.

docker rmi

Removes Docker images from your local system. Useful for cleaning up unused images and freeing disk space.
You can’t remove an image if running containers are using it (unless you force it with -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.
Credentials are stored locally, so you only need to log in once per registry. For Runpod, you’ll typically push images to Docker Hub or a private registry, then configure your endpoint or Pod to pull from that registry.

docker push

Uploads a Docker image to a registry, making it available for deployment.
Before pushing, make sure you’ve tagged your image with your registry username or private registry URL. For Runpod:

docker pull

Downloads a Docker image from a registry to your local system.
If you don’t specify a tag, Docker pulls the 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.
Avoid using :latest for production deployments. The :latest tag changes every time someone pushes a new image without specifying a version. This can cause several problems:
  • Unpredictable deployments: You can’t guarantee which version of your code is running.
  • Debugging difficulties: When problems occur, you can’t easily determine which image version caused them.
  • Caching conflicts: Runpod caches images for faster startup. If you push a new :latest image, your workers or Pods may continue using the cached version.
  • No rollback path: Without version tags, you can’t quickly revert to a previous working version.
Instead, use semantic versioning (e.g., myapp:v1.0.0) or commit-based tags (e.g., myapp:abc123). This makes deployments predictable and debugging straightforward.

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.
Common options:
  • -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.
The output shows container ID, image, command, creation time, status, ports, and name. Container IDs and names are useful for other commands like 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.
Stopped containers remain on your system until you remove them with docker rm.

docker start

Starts a stopped container. Unlike docker 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.
For Runpod Serverless, you can view worker logs through the web console. For Pods, 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.
This is invaluable when you need to inspect files, check processes, or debug issues in a running container.

docker inspect

Returns detailed low-level information about containers or images in JSON format.
Useful for getting IP addresses, environment variables, mount points, and other configuration details.

Volumes

These commands manage persistent storage for containers.

docker volume create

Creates a named volume that can persist data beyond container lifecycles.
Named volumes are managed by Docker and stored in a Docker-managed location on the host. For more on volumes, see the persist data guide.

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.
Containers on the same network can communicate using container names as hostnames.

Common workflows

Here are typical command sequences for common tasks.

Build, tag, and push a custom image

Use semantic versioning (e.g., v1.0.0) instead of :latest to ensure predictable deployments and easy rollbacks.

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: