
When installing any new software, it's always a good idea to update your Ubuntu system first. This will keep you at the current version with all recent updates and security patches applied. Run these two commands:
apt-get update
apt-get upgrade -y
Installation of Docker
Now that your system is up to date, you can actually install Docker itself with this command:
apt-get install -y docker.io
Once it has finished, launch Docker using the command:
systemctl start docker
To ensure that Docker starts on boot, run:
systemctl enable docker
If Docker installed properly, checking the installation and showing the Docker version is as simple as:
docker version

Now that Docker is installed, you are going to create some containers by downloading Docker images from the Docker Registry.
Basic Docker Usage
On this part, I go through the commonly used Docker commands, that is downloading a Docker image, creation of a container, and how to access the container.
Search for Docker Images
Before creating a new container, you need to select a base image. All of any other services need an operating system. You search for images that have been ubuntu based as shown below.
docker search ubuntu
This will list all available Ubuntu images.

Download a Docker Image
Once you have selected an image, download it onto your server by typing the following command:
docker pull ubuntu

With docker pull imagename
, the command downloads the image from Docker Hub (or any other Docker Registry) on your server.
To list all downloaded images, run the following:
docker images

How to Create and Run a Docker Container
Now that you have the Ubuntu image, you can create a container using any one of these commands:.
This will create a container without starting it.
docker create ubuntu:16.04

The following example will create and run a container in one go.
docker run -i -t ubuntu:16.04 /bin/bash
This command creates and runs the container from an image of Ubuntu 16.04 with a Bash shell inside the container. You are automatically connected to the shell of the container.
It will exit as soon as the shell you open is exited. To run the container in the background add the -d
option:
docker run -i -t -d ubuntu:16.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
The subsequent command will execute a simple Bash script, which just keeps echoing "hello world," in the background.
Managing Docker Containers
To view all running containers, use:
docker ps
To view the logs that can be generated by a container, one runs the following command:
docker logs [ContainerID]
If you need to access the shell of a running container in the background:
docker exec -i -t [ContainerID] /bin/bash
This will bring you into the shell on the container. The hostname and the container ID are the same; it means you are inside a container. When you run exit
, you leave the shell, but the container is still running.
To stop a container without removing it:
docker stop [ContainerID]
The stopped container can later be started by:
docker start [ContainerID]
If you would like to delete the container first, stop it and then remove it by:
docker rm [ContainerID]
Docker is an open-source platform for container virtualization. It helps developers deploy applications, and it allows system administrators to run them in a secure, isolated environment. This tutorial provides a very brief insight into how Docker is installed and used on Ubuntu. For more information, refer to official Docker documentation.
This version has the same technical content while optimizing the tone and flow.