Installation Of Docker On Ubuntu :
Remove old installation if it is installed
sudo apt-get remove docker docker-engine docker.io containerd runc
Update the Ubuntu packages & install the packages
sudo apt-get update sudo apt-get install ca-certificates curl gnupg
Install Docker official GPG key
sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg
Command to set up the repository:
echo \ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install the latest Docker package
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Verify the docker installation
sudo docker --version
Basic Commands :
Check version
docker --version
To check all downloaded / present docker images
docker images
Docker Login
docker login
To find the images in the docker hub
#docker search <nameofimage> docker search jenkins
Download any image
#docker pull <nameofimage> docker pull jenkins
To check the service
service docker status
Start Container
#docker start <containername/containerid> docker start mynginx
Stop Container
#docker stop <containername/containerid> docker stop mynginx
Kill Container
#docker kill <containername/containerid> docker kill mynginx
To see all running container
docker ps
To see all running and stopped container
docker ps -a
Remove the docker image
#docker rmi <imagename> docker rmi jenkins
Remove the container
#docker rm <containername/containerid> docker rm jenkins
Prune the container
docker system prune
Create the image from the docker file
#docker build -t <tagname> <absoulte_path> docker build -t LatestNginx /home/docker/Dockerfile OR docker build -t LatestNginx .
Create a container
#docker run -it --name <nameofcontainer <imagename> /bin/bash docker run -it --name LatestUbuntu Ubuntu /bin/bash
Connect to the container
#docker attach <containername/containerid> docker attach LatestUbuntu
Check the logs of a container
docker container logs <containername/containerid> docker logs abebb534sff3