Docker for Beginners: A Complete Guide to Installation and Essential Commands
Introduction
Docker has become one of the most widely used tools in modern DevOps workflows, and for good reason. It lets developers package an application together with everything it needs code, runtime, libraries, and system tools into a single lightweight unit called a container. That container runs the same way on your laptop, a test server, or in production, which eliminates the classic “it works on my machine” problem.
If you’re just getting started with Docker, this guide walks you through installing it on Ubuntu and covers the essential commands you’ll use every day, from pulling your first image to managing containers, volumes, and network ports.
What Is Docker?
Docker is a platform for building, shipping, and running applications inside isolated environments called containers. Unlike a full virtual machine, a container shares the host system’s kernel, which makes it much faster to start and far more efficient with system resources.
Installing Docker on Ubuntu
Setting up Docker on an Ubuntu machine involves a few straightforward steps. The commands below work the same way across most Linux distributions, though installation steps can vary slightly depending on your base OS.
Step 1: Install Required Dependencies
sudo apt-get install -y --no-install-recommends \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
Step 2: Add the Docker GPG Key
curl -fsSL https://apt.dockerproject.org/gpg | sudo apt-key add -
Step 3: Add the Docker Repository
add-apt-repository \ "deb https://apt.dockerproject.org/repo/ \ ubuntu-$(lsb_release -cs) \ main"
Step 4: Update Package Lists
apt-get update
Step 5: Install the Docker Engine
apt-get -y install docker-engine
Docker’s Basic Directory Structure
Once installed, Docker stores its data in a predictable set of directories:
| Path | Purpose |
|---|---|
/var/lib/docker | Base directory for all Docker data |
/var/lib/docker/container | Stores container information |
/var/lib/docker/container/<container-longname>/hostconfig.json | Full host configuration details for a container |
/var/lib/docker/volumes/<volumeID>/_data | Persistent data created inside a container’s volume |
Essential Docker Commands
Running Your First Container
Test your installation by pulling and running the classic hello-world image:
docker run hello-world
To pull an Ubuntu image and drop into an interactive terminal:
docker run -it ubuntu bash
Working with Images
View all images available locally:
docker images
Tag an image before pushing it to a registry:
docker tag 73fd91f23a84 pheonixsolutions/docker-whale:latest
(73fd91f23a84 is the image ID.)
Pushing and Pulling Images from Docker Hub
Create a free account at hub.docker.com, then log in from the terminal:
docker login
Push a tagged image to your Docker Hub repository:
docker push pheonixsolutions/docker-whale
Pull and run an image from a repository:
docker run pheonixsolutions/docker-whale
Managing Containers
Start an interactive container session:
docker run -ti ubuntu:14.04 /bin/bash
Press Ctrl + P + Q to detach from the container without stopping it.
List currently running containers:
docker ps
Reattach to a running container using its ID:
docker attach c26fe223abeb
List all containers, including stopped ones:
docker ps -a
Start a stopped container:
docker start 196b121e371b
Stop a running container:
docker stop 196b121e371b
Run a named, detached container:
docker run -d -ti --name=pheonixcontainer ubuntu:14.04 /bin/bash
Here, -d detaches the container so it runs in the background, and --name assigns it a readable name.
Working with Volumes
Mount a volume inside the container at /data:
docker run -ti -v /data --name=pheonixvolume ubuntu:14.04
Mount a specific host directory into the container:
docker run -ti -v /home/pheonixsolutions:/data --name=pheonixvolume ubuntu:14.04
The -v flag defines the container’s mount point.
Mapping Ports
Expose a container port (e.g., for MySQL):
docker run -d -p 3306 -ti --name=mysql1 mysql /bin/bash
Forward a specific host port to the container:
docker run -d -p 80:80 -ti --name=mysql2 mysql /bin/bash
The 80:80 mapping forwards requests on host port 80 to the container’s port 80.
Conclusion
Docker simplifies how applications are built, packaged, and deployed by wrapping everything an app needs into a portable container. Once you’re comfortable with the basics installing Docker, pulling and tagging images, managing containers, and mapping volumes and ports you have the foundation needed to explore more advanced DevOps workflows like Docker Compose and container orchestration with Kubernetes.
Start small: run the hello-world image, spin up an Ubuntu container, and get hands-on with the commands above. The best way to learn Docker is by using it.
Related Articles:

Happy to know you find this post useful. Cheers!
I have learn a lot through your post. This is the best and ever green blog