DOCKER Commands cheatSheet

Images 💿

Create a new image

docker build -t <image_name> .

Remove all unused images

docker image prune -a

Containers 📦

Create a new container (not sure what is this used for)

docker create

Get the process status of the containers

docker ps -a

Works as above but is the ‘newer’ way

docker container ls -a

Remote a stopped container

docker rm <container_name>

Remove ALL old stopped containers

docker container prune

Running Containers 👟

Start a container

docker run <container-name>

Stop a container

docker stop <container-name>

Auxiliary flags 🏳️

Add a name to an instance

--name <instance-name>

Run in detached mode: (Not attached to the current terminal UI)


Interactive mode


Remove container when done/stopped/fails


Port mapped from inside to the outside

-p 3000:3000

Run container in a specific network

--network <network-name>

Get help in any command


Debugging 🕵️

Show logs from a container

docker logs <container-name>

Show last 100 line logs from a container

docker logs --tail 100 <container-name>

Volumes 📁

Anonymous volume

docker run -v /app/data

Named volume

docker run -v <name>:/app/data

Bind Mount

docker run -v /<path_to_local_code>:/app/code

Remove existing volume

docker volume rm <name>

List of volumes

docker volume ls

Remove all the volumes

docker volume prune 

Networks 🔗

Create a new network by the name of ‘network-name’

docker network create <network-name>

Display the existing networks:

docker network ls

Docker Composer

Run specific containers/services with the up command Note: use -d FLAG to start in detached mode

docker-compose up -d server php mysql

Get docker compose down use: Note: Deletes containers, networks and shuts everything down, add the -v FLAG to remove the volumes

docker-compose down

After adding the depends_on we can run only:

docker-compose up -d server

Revaluation if something changed to build the image we run:

docker-compose up -d --build server