Skip to content

Instantly share code, notes, and snippets.

@avinashsivaraman
Created April 18, 2019 15:20
Show Gist options
  • Save avinashsivaraman/5a266191ae5ba71b887983dad77d15bb to your computer and use it in GitHub Desktop.
Save avinashsivaraman/5a266191ae5ba71b887983dad77d15bb to your computer and use it in GitHub Desktop.

An Ultimate Cheat Sheet for Docker

Docker is a open source platform to run and ship applications. For brief introduction about the docker. Dockers mainly contains images and containers. We can create any kind of containers in different way based on the images available. We can download images from hub.docker.com. If you want to know more about docker images and container This post mainly contains most frequently used docker commands to handle containers and images By running just docker in your terminal will list down all the executable commands

docker

We can always run docker command  - help to get information about any command

Creating a Container

docker create - name=demo -it ubuntu bash

Docker uses the technique image caching. If the image is new, it will download the image and cache it in our machine. To get more information about create

docker create - help

List all the running container

docker container ls

To see all the container(Running and inactive )

docker container ls -a

To start the docker

docker start demo

If you run the docker container ls now. You can see our running state of our docker

Run a new container:

This command is the combination of create and start command

Usage: docker run <image> <command>

Example with options:

docker run - name=bar -it ubuntu bash

To open our docker in interactive mode

docker attach demo

This will open the docker container in your terminal. Ubuntu image which we used will only have minimal setup. We need to install all packages we needed.

To see the logs of docker

docker logs demo

Remove a container:

Usage: docker rm <container name or id>

docker rm foo
#Force remove: docker rm foo -f

Remove all containers:

docker container ls -aq | xargs docker container rm

Docker Images

Remove an Image:

Usage: docker rmi <Image Name or id>

docker rmi b0dcbb03ed8d
# We can delete multiple docker image by 
# stacking the image id/name one after another
docker rmi b0dcbb03ed8d 74ead862bbeb

Remove all images:

docker image ls -aq | xargs docker rmi -f

Search for a docker image:

Usage: docker search <image>

docker search ubuntu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment