Useful Docker Commands

Docker has revolutionized the way we deploy and manage applications by providing a lightweight, portable, and scalable containerization platform. As developers and system administrators, mastering Docker commands is crucial for efficient container management. In this blog post, we’ll explore some common Docker commands that will help you streamline your containerized workflow.

Docker Run

docker run <containername> <imagename>

port can also be specified using -p argument e.g.

docker run -p 8080:80 mycontainer containerimage

Run a container in background

docker run -d -p mycontainer containerimag

Build a docker Image

docker build -t aa-imagename .

List all docker Images

docker image list

Prune all docker images

docker image prune --all

Run Docker Compose

Docker-compose up -d

Container Status

Docker-compose ps

Stop Containers

docker-compose stop 

Remove Orphan Containers

docker-compose up -d --remove-orphans

Stop specific container

docker stop <containerName>

docker kill <containerName>

List all Containers

docker container ls -a

Stop all containers

docker kill $(docker ps -q)

Remove a containers

docker rm <containerName>

Remove all containers

docker rm $(docker ps -a -q)

Tail a container log

docker logs --follow <containerName>


How to SSH into a running container

  1. Get running container name using – docker ps or docker-compose ps
  2. Use the command below to get a bash shell in the container
docker exec -it <container name> /bin/bash

Leave a comment

Create a website or blog at WordPress.com

Up ↑