Docker is an application that simplifies the management of application processes in containers. Containers allow applications to run in resource-isolated processes. They are similar to virtual machines, but containers are more portable, resource efficient, and more dependent on the host operating system.
For a detailed introduction to the various components of the Docker container, see The Docker Ecosystem: An Introduction to Common Components.
In this tutorial, you will install and use Docker Community Edition (CE) on Ubuntu 18.04. You install Docker yourself, work with containers and images and upload the image to the Docker repository.
Prerequisites
One Ubuntu 18.04 host or a virtual machine
Docker Hub account
Step 1 – Docker Installation
Update package
sudo apt update
Pre-requisites
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add GPG keys
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add docker resources
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
Update package manager
sudo apt update
Check and confirm for docker repo
apt-cache policy docker-ce
Output
##OUTPUT##
docker-ce:
Installed: (none)
Candidate: 18.03.1~ce~3-0~ubuntu
Version table:
18.03.1~ce~3-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
Step 2- Install Docker
sudo apt install docker-ce
Allow root permission to docker
sudo usermod -aG docker ${USER}
su - ${USER}
id -nG
sudo usermod -aG docker username
username : It should be your username
To View Docker Information
docker info
Step 3 – Conatiner and Images Docker commands
Example to download official UBUNTU image to your computer
docker pull ubuntu
To view the image you have download
docker images
To run a docker container
docker run -it ubuntu
To view active and inactive docker container
docker ps -a
To view latest docker container
docker ps -l
To stop a running docker container
docker stop <container name>
To remove a docker conatiner
docker rm <container name>
Pushing Docker Images to Docker Repository
Login first into Docker Hub
docker login -u <docker-registry-username>
Note : If the docker registry username is different from local username, you need to tag your image with registry username.
docker tag <tag_name>/ubuntu-nodejs <docker-registry-username>/ubuntu-nodejs
Now push your own image
docker push <docker-registry-username>/ubuntu-node.js
FINALE
You now have a working Docker. We tried and understood images and containers with docker commands.