Skip to main content

Common Docker Commands

Our platform supports using Docker commands to build, run, and manage containers as part of your development workflow. This section provides a quick reference for some of the most frequently used Docker commands.

Login

Before pushing or pulling images from a registry (such as Docker Hub), you need to log in to authenticate. This saves your credentials locally for future use.

docker login
docker login -u myusername

Managing Images

Docker images are the blueprint for your containers. Below are common commands for interacting with images:

  • Uploading a container image to a registry like Docker Hub:
docker push
  • Downloading a container image from a registry:
docker pull
  • Listing all container images stored locally:
docker images
  • Removing a Docker image from your machine:
docker rmi

Examples:

  • Pushing a custom image to the registry:
docker push myuser/myimage:v1
  • Pulling a shared image:
docker pull someimage
  • Listing all downloaded images:
docker images
  • Deleting the specified image:
docker rmi <image>

Managing Containers

Containers are running instances of Docker images. Use these commands to manage your containers:

  • Starting a new container from an image:
docker run
  • Listing running containers:
docker ps
  • Display logs from a specific container:
docker logs
  • Stop or remove a running container:
docker stop / docker rm

Examples:

  • Starts a container: docker run
  • Lists active containers.
docker ps
  • Shows logs for the specified container.
docker logs <container>
  • Stops a running container.
docker stop <container>
  • Removes a container.
docker rm <container>

Building Docker Images

To create a new Docker image from a Dockerfile, use the following command:

  • Building an image from a Dockerfile:
docker build

Example:

  • Building an image based on the current Dockerfile:
docker build
  • Building an image for a specific architecture.
docker build --platform=linux/amd64

Volumes

Volumes allow you to persist data beyond the lifecycle of a container. Use these commands to create and manage Docker volumes:

  • Creates a new persistent volume:
docker volume create
  • Attaches a volume to a running container:
docker run -v

Examples:

  • Creating a new volume:
docker volume create
  • Mounting the volume inside a container:
docker run -v <volume>:/data

Networks

Docker networks allow containers to communicate with each other in isolation. These commands help manage container networks:

  • Creating a user-defined virtual network.
docker network create
  • Connecting a container to a specific network:
docker run --network=<name>

Examples:

  • Creating a new network.
docker network create
  • Connecting a container to the specified network.
docker run --network=<name>

Executing Commands in Containers

To run commands inside a running container for debugging or inspection, use:

  • Executing a command in a running container.
docker exec

Example:

  • Lists the files in /etc directory inside the specified container.
docker exec <container> ls -l /etc

By using these commands, you can efficiently manage your containerized workloads, networks, volumes, and images in a Docker-based environment.