This guide provides a step-by-step walkthrough of fundamental Docker concepts and commands. It's designed as a practical lab manual to get you started with containerization.
Prerequisites
This section guides you through installing the Docker Engine on your Ubuntu system. We'll remove old versions, set up the official Docker repository, and install the latest stable version.
Remove any old Docker versions
containerd
or runc
.sudo apt-get remove \\
docker \\
docker-engine \\
docker.io \\
containerd \\
runc
Update package index and install prerequisites
apt-transport-https
, ca-certificates
, curl
, software-properties-common
) are necessary for adding and accessing external repositories over HTTPS.sudo apt-get update
sudo apt-get install \\
apt-transport-https \\
ca-certificates \\
curl \\
software-properties-common
Add Docker’s official GPG key
curl -fsSL <https://download.docker.com/linux/ubuntu/gpg> \\
| sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Set up the stable repository
apt
where to find the Docker packages for your specific Ubuntu version (lsb_release -cs
) and architecture (dpkg --print-architecture
). The signed-by
part links the repository to the GPG key we added.echo \\
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \\
<https://download.docker.com/linux/ubuntu> \\
$(lsb_release -cs) stable" \\
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine and CLI
docker-ce
(the Community Edition engine), docker-ce-cli
(the command-line interface), containerd.io
(the container runtime), and necessary plugins for building and orchestration (docker-buildx-plugin
, docker-compose-plugin
).sudo apt-get update
sudo apt-get install \\
docker-ce \\
docker-ce-cli \\
containerd.io \\
docker-buildx-plugin \\
docker-compose-plugin
Verify installation
docker
command is available and reports its installed version, confirming the installation was successful.docker --version
(Optional) Manage Docker as a non-root user
root
. Only root or users in the docker
group can access it. Adding your user to the docker
group allows you to run docker
commands without sudo
. Note: The docker
group grants root-level privileges, so handle with care.sudo usermod -aG docker $USER
# Then log out and back in, or run:
newgrp docker
Docker Images are read-only templates used to create containers. They contain the application code, libraries, dependencies,1 and configuration needed for an application to run. This lab explores how to build, inspect, share, and manage images.
2.1 Build an image from a Dockerfile
Dockerfile
in the current directory (.
). The t myapp:latest
option tags the image with a name (myapp
) and a version (latest
), making it easy to reference.# From a directory with Dockerfile
docker image build -t myapp:latest .