Getting Started with Docker: A Beginner’s Guide to Containers
This article introduces Docker, explains its architecture and advantages over virtual machines, compares it with Vagrant, and provides a step‑by‑step tutorial for installing Docker on Fedora, pulling images, running a Node.js/Express app inside a container, and publishing the image to Docker Hub.
A few months ago Red Hat announced a partnership with dotCloud on Docker technology. At that time I didn’t have time to learn Docker, so today, during a 30‑day challenge, I decided to explore what Docker really is. This post is not about using Docker on OpenShift; see Mike McGrath’s “Technical Thoughts on OpenShift and Docker” and the related StackOverflow question for differences between Docker and OpenShift.
What is Docker?
Docker provides an envelope (container) to run your applications. It began as an experimental project at dotCloud, was later open‑sourced and renamed Docker Inc. It is written in Go and sits on top of LXC (Linux Containers), offering developers a higher‑level API.
Docker extends Linux Containers (LXC) by providing a lightweight virtual environment for each process through a high‑level API. It leverages LXC, cgroups, and the Linux kernel. Unlike traditional virtual machines, a Docker container does not contain a full operating system; it uses the host OS kernel while packaging the application and its dependencies.
Docker works as a portable container engine, packaging an application and all its runtime dependencies into a virtual container that can run on any Linux server, whether on public or private cloud, bare metal, or elsewhere, greatly improving flexibility and portability.
Docker consists of:
Docker daemon (server) that manages containers.
Docker command‑line client for controlling the daemon.
Docker images, which can be browsed at https://index.docker.io/ .
Why should I care?
Docker is useful because moving code from one machine to another is often difficult. Docker aims to make software migration more reliable and automated, and containers can run on any OS that supports Docker.
Read the article “how the Fedora Project is embracing Docker” for more details.
But I’m already using virtual machines (VMs)
Until now, the only reliable way to migrate programs has been virtual machines, which provide a full OS environment. VMs are heavyweight, containing unnecessary hardware drivers, virtual CPUs, network interfaces, etc., leading to large images, long boot times, and high resource consumption.
Docker is much lighter; it runs like a regular program. Creating an image and taking a filesystem snapshot is fast. Docker can run inside virtual environments such as EC2 or Rackspace VMs. On macOS and Windows, the best way to use Docker is via Vagrant. Docker’s goal is to provide VM‑like isolation while starting faster and using fewer resources.
Is it like Vagrant?
When deciding whether to use Vagrant or Docker for the next project sandbox, the answer is the same: Docker.
Docker consumes fewer resources than Vagrant, which relies on VirtualBox virtual machines. See the referenced StackOverflow answer for more information.
Oops! Another application packaging system
At first I wondered why we need another packaging system when I already package Java programs as JAR or WAR files. After reading more about Docker, I realized that a Docker application package bridges the gap between heavyweight VMs and lightweight code packages.
In Docker, an application package includes both the application code and the required runtime environment. For example, a Java web app is typically packaged as a WAR file containing only the code, but it still needs a specific deployment environment (e.g., Java 7 vs. OpenJDK 6, or Mac vs. RHEL). Docker packages both the code and its dependencies, ensuring consistent execution across different environments.
Getting started with Docker
On a Fedora machine, install Docker using the commands below:
$ vagrant up
$ vagrant sshThen pull the Fedora Docker image: $ sudo docker pull mattdm/fedora The command downloads the image from https://index.docker.io/ . List all images after installation:
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
shekhargulati/node_image_007 latest e12b3054d981 50 minutes ago 470.3 MB (virtual 601.8 MB)
mattdm/fedora 12.04 8dbd9e392a96 7 months ago 131.5 MB (virtual 131.5 MB)Run a container from the Fedora image: $ sudo docker run -t -i -p 3000 mattdm/fedora /bin/bash Inside the container, list files with ls: $ ls Create a directory structure:
$ mkdir -p home/shekhar/dev
$ cd home/shekhar/devInstall Node.js: $ sudo yum install npm Install the Express framework: $ npm install express -g Create a new Express app and run it:
$ express myapp
$ cd myapp
$ npm install
$ node app.jsThe app starts on port 3000. In another terminal, list Docker processes:
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4a5715a915e5 mattdm/fedora /bin/bash 5 minutes ago Up 5 minutes 0.0.0.0:49157->3000/tcp red_duckPort 3000 inside the container is bound to host port 49157. Test the Express app with: $ curl 0.0.0.0:49157 Commit the container as a new image and push it to Docker Hub (you must register at https://index.docker.io/account/signup/ first):
$ sudo docker commit 4a5715a915e5 shekhargulati/node_image_007
$ sudo docker push shekhargulati/node_image_007Replace the username and image name with your own. The image is now available at https://index.docker.io/u/shekhargulati/node_image_007/ . Pull it with: $ docker pull shekhargulati/node_image_007 This concludes today’s content. Feedback is welcome!
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
