Skip to content

Instantly share code, notes, and snippets.

@Andreluizfc
Last active July 3, 2023 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andreluizfc/e203e71286e81e01006754f9e3b8a9f8 to your computer and use it in GitHub Desktop.
Save Andreluizfc/e203e71286e81e01006754f9e3b8a9f8 to your computer and use it in GitHub Desktop.
Docker Commands

DOCKER Cheat Sheet

Build and run

docker build -t project/my-app .
docker run --name name-of-container -p 8080:8080 --detach project/my-app

List containers

docker ps
docker ps -a

Stop containers and remove:

docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
docker rmi $(docker images -q)

Remove Volumes

docker volume rm $(docker volume ls -q)

Prune System and Cache

docker system prune -a
docker builder prune --all

Observe image bash:

docker exec -it [container_id] /bin/bash
docker exec -u root -it [container_id] /bin/bash

Inspect

You can examine a container's metadata in Docker by using Docker inspect:

docker inspect [container_id]

Docker Compose

Build with no cache

docker-compose build --no-cache

Build and up

docker-compose up -d --build

If cache stays in memory

docker-compose up --force-recreate

Where to find Volumes

Windows + WSL 2 (Ubuntu 18.04).

Type in the Windows file explorer :

For Docker version 20.10.+ : \\wsl$\docker-desktop-data\data\docker\volumes
For Docker Engine v19.03: \\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment