What is Docker? How to install docker on ubuntu system?
What is Docker?
Docker is a container-based application. It contains all the dependencies to run a specific application or services. To ship container on production server also easy. Moreover, it reduces the need for a virtual machine to test the applications or services.
This article will help you step by step to install docker in ubuntu 18.04 systems.
Advantages of Docker
Benefits using docker are given below.
1. Cost Saving
2. Continuous testing and deployment
1. One Ubuntu 18.04 system.
2. User with Sudo privileges.
Step 1: Install Docker in ubuntu
Run the following command to install Docker community edition.
sudo apt install docker.io
Step 2: Start Docker Service
To start Docker service run the below command.
sudo systemctl start docker
Run the following command to start Docker service on system startup.
sudo systemctl enable docker
You can also check the installed Docker version.
Step 3: How to Use Docker
Docker installation on the system is successful. Now the next step is to learn how to use it. Remember Docker containers run from Docker images. By default, it pulls images from the Docker hub.
Search Docker Image
The syntax for Docker image searching is “docker search <ubuntu>”
For example, to search for Ubuntu image, run the below command:
docker search ubuntu
Download Docker Image
As above command display the available ubuntu image. Choose the desired ubuntu image. Download it on the local system using pull subcommand. As shown in the below screenshot.
docker pull ubuntu
Run the following command to check the downloaded images on the local system.
Step 4: Run a Docker Container
Let’s launch a Docker container using the above-downloaded ubuntu image.
docker run -it ubuntu
Where -i and -t switches used to give interactive shell access.
How to exit from Docker Container
Type Ctrl+p+q to exit from the docker container.
Execute the following command to check the running container.
Apart from it, you can also check both the containers (Active and inactive).
docker ps -a
Step 5: How To Start/Stop Docker Container
Docker container id is needed to start or stop it. You can check the docker container id from the above command i.e. docker ps
To start a container :
docker start <container-id>
To stop a container :
docker stop <container-id>
Step 6: Remove a Docker Container
First, run the ps -a command to get the container id or name. Next, run the below command to remove a container from the system.
docker rm <container-id>
Read More: Install and Manage Node.js Version
Conclusion: You have perfectly learned step by step how to install and use Docker.