Docker CLI Commands Cheatsheet

Test the Docker version
docker --version

To view more details about your docker installation
docker info

List all images from local storage
docker images

List all running docker containers
docker container ls
docker ps

List all docker containers (including stopped)
docker container ls -a
docker ps -a

Running docker containers
docker run hello-world

Running docker containers in background
docker run -dt jenkins

Running docker containers with port mapping
docker run -dt -p 8080:8080 jenkins

Running docker container by assigning a name
docker run -dt --name jenkins -p 8080:8080 jenkins

Running docker containers by  creating a volume.
docker run -dt --name jenkins -p 8080:8080 -v /opt/jenkins_workspace:/var/jenkins_home jenkins

Running container process with provided user
docker run -dt --name jenkins -p 8080:8080 -u jenkins -v /opt/jenkins_workspace:/var/jenkins_home jenkins

Running docker container by passing environment variables
docker run -dt --name jenkins -p 8080:8080 -e MAVEN_HOME=/opt/maven jenkins

To view all configuration information of an image
docker inspect jenkins

To view all history of an image
docker history jenkins

Pushing Docker images to DTR
docker push jenkins

Tagging Docker images
docker tag jenkins jenkins:1.0

Docker container life cycle commands 
To create docker container
docker create --name myjenkins jenkins

Run the docker container
docker run -dt --name myjenkins jenkins

Pause jenkins - It will pause all containers running in docker container
docker pause myjenkins

Unpause docker container
docker unpause myjenkins

Stop running container
docker stop myjenkins

Start the stopped container
docker start myjenkins

Restart the docker container
docker restart myjenkins

Kill the docker container
docker kill myjenkins

Destroy the docker container
docker rm myjenkins

Destroy the docker container including volume
docker rm -v myjenkins

Packing and Unpacking containers
Creating docker image from running container
docker commit myjenkins jenkins:1.0

Save docker container as tar file
docker save myjenkinsm -o jenkins1.tar

Load Docker image from tar file
docker load -i jenkins1.tar



<< Previous                                                                                                                          Next >>


1 comment: