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

Install Atom on Ubuntu 18.04: GitHub’s Code Editor APT Setup

Atom is a free, open-source, cross-platform code editor developed by GitHub. Built on Electron, it uses…

25 minutes ago

Install MariaDB on Ubuntu 18.04: Two Methods and Secure Setup

MariaDB is an open-source, multi-threaded relational database management system and a fully backward-compatible replacement for MySQL.…

12 hours ago

Install Odoo 11 on Ubuntu 18.04: Virtualenv and Nginx Proxy Setup

Odoo 11 is an open-source all-in-one business software platform covering CRM, e-commerce, billing, accounting, manufacturing,…

12 hours ago

Install Odoo on Ubuntu 18.04: Deploy Version 12 with Nginx

Odoo is the most widely used open-source all-in-one business software suite. It integrates CRM, e-commerce, billing,…

12 hours ago

Install phpMyAdmin with Nginx on Ubuntu 18.04: Setup and Config

phpMyAdmin is a free, open-source PHP application for managing MySQL and MariaDB servers through a browser.…

12 hours ago

Install phpMyAdmin on Ubuntu 18.04 with Apache: Setup Guide

phpMyAdmin is a free, open-source PHP application that provides a browser-based interface for managing MySQL and…

3 days ago