Docker is a free and open platform for developing, deploying, and running applications. Docker decouples your programmes from your infrastructure, allowing you to deliver software faster. With Docker, you can manage your infrastructure in the same way you manage your apps. By utilising Docker’s methodologies for rapid shipping, testing, and deploying code, you may significantly reduce the time between writing code and executing it in production.

Common Docker Commands for Every Developer

Find some of the common docker containerisation commands which are used by every docker developers.

Pull Docker Image

docker pull image_name

For this example we will be pulling ubuntu image in docker. You can finds images here which you like to pull

docker pull ubuntu

View all images on you local machine

Bellow command will display all pull docker images

docker image

Run docker image

docker run -it -d image_name

Run docker image in interactive and detach mode. Detach mode will run the docker in background.

docker run -it -d ubuntu

Check docker image running status

docker ps

Bellow command will display all images which are running

docker ps -a

Run docker image with custom name

docker run -it -d --name container_name image_name

Bellow command will create a ubuntu container with name mycontainer.

docker run -it -d --name mycontainer ubuntu

Run docker image with custom name and port

docker run -it -d -p 80:80 --name container_name image_name

Bellow command will create a ubuntu container with name mycontainer1 and open port with specified port number

docker run -it -d -p 80:8 --name mycontainer ubuntu

Go inside docker command

docker exec -ti container_name_or_container_id bash

Open container in bash mode. Bellow we will go inside mycontainer container which we created above

docker exec -ti mycontainer bash

Stop docker container

docker stop container_name_or_container_id
docker stop mycontainer

Start docker container

docker start container_name_or_container_id
docker start mycontainer

Kill docker container

How to forcefully kill docker container

docker kill container_name_or_container_id
docker kill mycontainer

Restart container

How to refresh the docker container for changes reflection.

docker restart container_name_or_container_id
docker restart mycontainer

Save container settings

docker commit container_name_or_container_id custom_image_save_name
docker commit mycontainer custom-ubuntu-image

Remove docker container

docker rm container_name_or_container_id

How to remove the docker container.

docker rm mycontainer

To permanent/forcefully delete docker container.

docker rm -f mycontainer

Remove docker image

docker rmi image_name
docker rm ubuntu

Next Tutorial – How to use Docker Hub and Registry