What is Docker ?
Docker is a open-source platform that allows user to build, package and run application inside a container.
How to install Docker in Ubuntu ?
Step 1:
Open the CLI terminal in Ubuntu and run this command to update software repositories.
sudo apt update
Step 2:
Install docker by following command:
sudo apt install docker.io -y
Step 3:
Enable and start docker service
sudo systemctl enable docker --now
Step 4:
Check the docker version
docker --version
How to execute Docker command without sudo ?
To achieve this, we need to add Ubuntu user to the docker group.
docker --versiosudo usermod -aG docker $USER
Now find out current add user is added to the docker group or not
getent group docker
Now refresh the group permission
getent group docknewgrp docker
Now restart docker
sudo service docker restart
How to create images from docker file ?
Build docker image from docker file
suddocker build -t <Name of the Dockerfile>
docker build -t myimg:latest .
Docker basic commands:
| Old Commands | New Commands | Purpose |
| docker ps | docker container ls | List containers |
| docker run | docker container run | Run a command in a new container |
| docker rm | docker container rm | Remove one or more containers |
| docker images | docker image ls | List images |
| docker rmi | docker image rm | Remove one or more images |
How to list all pulled images?
docker images
How to map port on a host?
docker run -p -d 8080:8080 ubuntu
How to login docker, build and push?
login:
docker login
build:
docker lodocker build -t image_name:tag .
push:
docker push <Image name/Image ID>
How to stop docker single container and multiple containers?
docker stop container_name_or_id
docker stop container1 container2 container3
How to restart and inspect docker ?
restart:
docker sdocker restart container_name_or_id
inspect:
docker inspect container_name_or_id
What is docker hub?
It is a cloud based registry for docker images. It contains vast repository of public images and official images for popular applications and services.
What is docker image?
It is a virtual template which is used to create containers, it is includes everything which are need to run an application such as OS, application code, libraries, dependencies. A docker file has a set of scripts or instructions which specify dependencies, environment variables etc and by a “docker build command”, user can create a docker image.
What is docker compose ?
Docker compose is a multi container managing tool. It is uses YAML file. With docker compose, user can start, stop and all other services with single command.