How To

Install Docker on Ubuntu 18.04: Setup, Images, and Containers

Docker is a containerization platform that lets you package applications and their dependencies into lightweight, portable containers. Those containers run consistently across any environment, your laptop, a staging server, or a cloud production cluster. Docker is the standard for container deployment and a core tool in modern DevOps and CI/CD pipelines.

This guide covers how to install Docker on Ubuntu 18.04 from the official Docker repository, how to run Docker commands without sudo, and how to work with images and containers using the Docker CLI.

<strong>Prerequisite:</strong>&nbsp;You need sudo access. All commands should be run as a non-root user.

Install Docker on Ubuntu from the Official Repository

The Docker package in Ubuntu’s default repositories is often outdated. Install from Docker’s official repository to get the latest stable release.

Install the required dependencies:

bashsudo apt updatesudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Import the Docker GPG key:

bashcurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker APT repository:

bashsudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Install Docker CE:

bashsudo apt updatesudo apt install docker-ce

Docker starts automatically after installation. Verify it is running:

bashsudo systemctl status docker

To upgrade Docker, use the standard sudo apt update && sudo apt upgrade process. To uninstall, run sudo apt purge docker-ce && sudo apt autoremove — but remove all containers and images first.

Run Docker Without sudo

By default, Docker commands require administrator privileges. Add your user to the docker group to run them without prepending sudo:

bashsudo usermod -aG docker $USER

Log out and log back in to apply the group membership change. Then verify the setup by running the official test container:

bashdocker container run hello-world

Docker downloads a small test image, runs it in a container, prints a “Hello from Docker” message, and exits. If you see that message, Docker is installed and working correctly.

Working with Docker Images

Docker image is an immutable snapshot of an application along with all its dependencies, libraries, and runtime instructions. Images are stored in registries. Docker Hub is the primary public registry and hosts thousands of official and community images, from base operating systems to databases and web servers. When no version tag is specified, Docker pulls the image tagged latest.

Search for an image on Docker Hub:

bashdocker search ubuntu

Download an image:

bashdocker image pull ubuntu

List all downloaded images:

bashdocker image ls

Remove an image:

bashdocker image rm ubuntu

Working with Docker Containers

Docker container is a running instance of an image. Think of the image as a blueprint and the container as what actually executes. You can run multiple containers from the same image simultaneously, and each one runs in isolation.

Start an interactive container based on the Ubuntu image:

bashdocker container run -it ubuntu /bin/bash

The -it flag opens an interactive terminal session inside the container. Your command prompt changes to show that you are now working from inside the container. Type exit to stop it and return to your host system.

List all currently running containers:

bashdocker container ls

To see all containers, including stopped ones:

bashdocker container ls -a

Remove a container by its ID:

bashdocker container rm [container_id]

Docker is now installed and running on your Ubuntu 18.04 machine. You can pull images from Docker Hub, launch containers in seconds, and manage the full container lifecycle from the command line. Leave a comment below if you run into any issues during setup.

Cyber Defence

Recent Posts

Enable SSH on Ubuntu 18.04: Install, Connect, and Manage

SSH (Secure Shell) is a cryptographic network protocol that creates a secure, encrypted connection between your…

1 hour ago

Install Node.js and npm on Ubuntu 18.04: Three Methods Compared

Node.js is an open-source, cross-platform JavaScript runtime that lets you run JavaScript on the server side,…

1 hour ago

Set DNS Nameservers on Ubuntu 18.04: Desktop and Server Guide

DNS (Domain Name System) is what translates domain names into IP addresses. When you type a…

2 hours ago

Install Yarn on Ubuntu 18.04: APT Setup and Essential Commands

Yarn is a fast, reliable JavaScript package manager that works alongside npm. It was built to fix…

2 hours ago

Install Webmin on Ubuntu 18.04: Web Control Panel Setup Guide

Webmin is an open-source, browser-based control panel for Linux server administration. Instead of managing your server…

1 day ago

Install Go on Ubuntu 18.04: Tarball Setup and Hello World Guide

Go (also called Golang) is a modern, statically typed programming language created at Google. It is…

1 day ago