🐬Docker Cheat Sheet

Docker is an open platform for developing, shipping, and running applications. Below cheat sheet for quickly brush up docker cli commands.

Docker Commands

Login

docker login -u "your username" -p "your password" docker.io

Build Docker File

To be executed in the root directory of 'DockerFile'

Build using Default File Name
docker build --tag geo-location-app:v0.1 .
Build By File Name
// First in the command you should be in the path of the file name 'SQLAPI-Dockerfile'
docker build --tag fx-data-apis-app:v0.1 -f SQLAPI-Dockerfile .

Push Image to hub.docker.com

Option 1

Push Image Option 1
docker tag 116e178f6fc5 ganeshramsr/geolocationapi:v0.1 
docker login docker.io docker push ganeshramsr/geolocationapi:v0.1

Option 2:

Push Image Option 2
docker tag 338f61b0d9c7 
ganeshramsr/geo-loc-api:v0.1 docker push ganeshramsr/geo-loc-api:v0.1

docker tag 2ea41a89aa54 
ganeshramsr/geo-loc-api:v0.2 docker push ganeshramsr/geo-loc-api:v0.2

To Run Docker image

Simple Docker Run

Simple Run
docker run -p 5050:80 --name <containername> <imagename>

Run docker image with environmental variable

Run Docker with Env

docker run -it -d -p 5050:80 
-e ASPNETCORE_URLS=http://+:80 
--name containername imagename

docker run --rm -it -p 49853:80/tcp 
-e GEO_API_URL='http://localhost:40051/' 1b37dbb57268

Run in 2 different ports

Run Cocker with Port

docker run --rm -it -p 49854:443/tcp -p 49853:80/tcp 1b37dbb57268

Run MongoDB
// Run Mongo DB Container with Volume Attached

docker run -d -p 27017:27017 --name mongo-db-container 
-v C:/Data/MongoDb-Data:/data/db -d mongo:latest

Run SQL Server
// Run SQL Server with SA, Password
docker run --name SQLServer2022 
-e "ACCEPT_EULA=Y" 
-e "MSSQL_SA_PASSWORD=System@1984" 
-p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest

Remove Actions

To remove Image/Container

Remove Image
docker image prune --filter="dangling=true"
Remove Image
docker image rm b01823902874
Remove Image by Force
docker image rm b01823902874 -f
Remove Container
docker container prune //Remove all unused containers

Container Actions

Start Container
// Starts the existing container
docker container start mongo-db-container

Save as '.tat'
//Extract Docker image and save it as '.tar' file.
docker save --output busybox.tar 3ca38f187e93

Inspect
// Inspect the running container
docker inspect 'container-id'

Stop Container
docker stop c15198355ebd

Primary Full Cheat Sheet for Docker CLI

Last updated

Was this helpful?