Installation of Docker
Remove any docker file running on the system using the below command,
sudo apt-get remove docker docker-engine
docker.io
Update the package database,
sudo apt-get update
Install docker using the below command,
sudo apt install
docker.io
Install all dependency packages,
sudo snap install docker
You can check the version of docker installed using this command,
docker --version
To check the docker installation is done correctly you can run the below command,
sudo docker run hello-world
Working with images
docker images
- List all images on the systemdocker build . -t <image_name> <path>
- Build an image from a Dockerfile in the specified pathdocker push <image_name>
- Push an image to a registry(docker-hub)docker pull <image_name>
- Pull an image from a registry(docker-hub)docker rmi <image_name>
- Remove an imagedocker image prune
- Remove all unused image
Working with containers
docker run -d <image-name>
- Create and start a container based on the specified imagedocker start <container-id>
- Start a stopped containerdocker stop <container-id>
- Stop a running containerdocker kill <container-id>
- To kill the containerdocker rm <container-id>
- Remove a containerdocker ps
- List all running containersdocker ps -a
- List all containers (running and stopped)
Working with volumes
docker volume create <volume-name>
- Create a named volumedocker volume ls
- List all named volumesdocker volume rm <volume-name>
- Remove a named volume
Docker commands
docker exec <container-id> <command>
- Run a command inside a running containerdocker inspect <image-or-container>
- Show detailed information about an image or containerdocker logs <container-id>
- Show the logs of a running containerdocker login
- Login to a Docker registrydocker logout
- Logout from a Docker registry
These are some Docker commands which are used by me in day-to-day tasks.