Docker Cheat Sheet
#Install Docker in Ubuntu
$sudo apt-get install docker
#Check the installed version of the docker
$docker --version
Container Lifecycle
#Create a container without starting it
$docker create [IMAGE]
#Rename a container
$docker rename [CONATAINER_NAME] [NEW_CONTAINER_NAME]
#Create and start a container
$docker run [IMAGE_NAME/ID]
#Remove a container after it stop
$docker run --rm [IMAGE_NAME/ID]
#Start a container and keep it running
$docker run -it d [IMAGE]
#Create, start the container and run a container; remove the container after executing the command
$docker run -it -rm [IMAGE_ID/IMAGE_NAME]
#Delete a container if it's not running
$docker rm [CONATAINER_ID/CONTAINER_NAME]
Image LifeCycle
#Create an image from a Dockerfile
$docker build https://github.com/yourusername/your-repository.git
#Build an image from a Dockerfile and tag it
$docker build -t Name:v1.0.
#Push an image to the Docker registry
$docker push [IMAGE_NAME]
#Pull an image from the Docker registry
$docker pull [IMAGE]
#Create an image from a container
$docker commit [CONTAINER] [NEW_IMAGE_NAME]
Networking
#List Networks
$docker network ls
#Remove one or more networks
$docker network rm [NETWORK_ID/NETWORK_NAME]
#Show information on one or more networks
$docker network inspect [NETWORK_ID/NETWORK_NAME]
#Connect a container to the network
$docker network connect <NETWORK_ID> <CONTAINER_NAME>
#Disconnect a container to the network
$docker network disconnect <NETWORK_ID> <CONTAINER_NAME>
Start & Stop
#start a container
$docker start [CONAINTER_NAME/CONTAINER_ID]
#Stop a running container
$docker stop [CONTAINER_NAME/CONTAINER_ID]
#Stop a running container and start it up again
$docker restart [CONTAINER_NAME/CONTAINER_ID]
#Pause processes in running container
Subscribe to my newsletter
Read articles from Samara Reddy directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by