October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Docker for Beginners: How Images, Containers, and Commands Work

Docker uses images as reusable templates and containers as running instances. Learn the difference and try beginner commands to run and build them.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Docker packages applications and their dependencies into images, then runs those images as isolated containers. An image is the reusable, read-only template; a container is a running instance of that template. That distinction makes the basic workflow easier to understand: pull or build an image, start a container, inspect it, and stop or remove it when you are done.

What is Docker?

Docker is a platform for developing, shipping, and running applications. Its tools help package an application and the files and configuration it needs, distribute that package, and run it in a container. Docker’s beginner documentation introduces the platform and its core workflow.

As an Amazon Associate I earn from qualifying purchases.

Containerization is the practice of packaging an application and its dependencies so it can run in an isolated container environment. Containers are not full virtual machines: a container is a process running with isolation and configuration supplied by the container platform. Packaging can make deployment more consistent, but it does not guarantee identical behavior on every operating system or remove security risks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What is a container?

A container is a runnable instance of an image. It has an isolated process tree and filesystem, along with configured networking and storage. A container can be started, stopped, and removed independently of the image it came from.

When a container runs, it has a writable layer for changes made during its lifetime. Removing the container also removes changes held only in that layer. Data that must outlast the container needs persistent storage, such as a volume, rather than relying on the disposable layer.

What is a Docker image?

A Docker image is a read-only package used as a template to create containers. It contains the files and configuration needed to run an application and is built from layers. One image can be used to create multiple containers; each container gets its own writable layer.

Aspect Image Container
Purpose Read-only template for running an application Runnable instance created from an image
Changes Built as image layers Runtime changes go into a writable layer
Lifecycle Can be used to create multiple containers Removing it discards unpersisted changes

A registry stores and distributes images. Docker Hub is a public registry and is the default image lookup location in Docker’s documented default setup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I run a Docker container?

Docker’s docker run command creates and starts a container from an image. If the image is not already local, Docker may fetch it from the configured registry. In this example, an NGINX image runs in the background and its container port 80 is published to port 8080 on the host:

docker pull nginx
docker run -d --name web -p 127.0.0.1:8080:80 nginx

Visit http://127.0.0.1:8080 on the same computer to reach the published service. The -p option maps a host port to a container port. Binding to 127.0.0.1 makes this example accessible through the host’s loopback interface; if you omit a host IP, current Docker documentation says a published port binds on all interfaces by default. See Docker’s references for running containers and port publishing.

Useful commands for inspecting and cleaning up this example are:

docker ps
docker ps -a
docker logs web
docker stop web
docker rm web
  • docker ps lists running containers; add -a to include stopped ones.
  • docker logs web displays output from the container named web.
  • docker stop web stops that container; docker rm web removes it after it has stopped.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How do I build a Docker image?

To build an image, write a Dockerfile: a text file containing instructions for the image builder. These common instructions cover the base image, working directory, files to copy, build-time commands, and default command:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • FROM selects a starting image.
  • WORKDIR sets the working directory for later instructions.
  • COPY copies files from the build context into the image.
  • RUN executes a command while the image is being built.
  • CMD specifies the default command when a container starts.

For a small example, create a file named Dockerfile in an empty project directory:

FROM nginx
COPY site/ /usr/share/nginx/html/

Put the site files in a site subdirectory, then run these commands from the directory containing the Dockerfile:

docker build -t my-app:1.0 .
docker run --rm -d --name my-app -p 127.0.0.1:8080:80 my-app:1.0

Here, docker build reads the Dockerfile and builds an image tagged my-app:1.0. The final . is the build context: the current directory and the files the builder can use. The second command starts a container from the image, maps the service to the host’s loopback address, and removes the container when it stops because of --rm. The site directory must be inside the build context for the COPY instruction to access it. Docker explains these basics in its guides to writing a Dockerfile and build context.

What does EXPOSE do, and why might a port not be reachable?

The Dockerfile instruction EXPOSE documents a port the application is intended to listen on inside the container. It does not publish that port to the host. To make a service reachable from the host, publish a mapping when starting the container, for example -p 127.0.0.1:8080:80 for host port 8080 to container port 80. If the service still cannot be reached, check that the container is running, that the application listens on the expected container port, and that the mapping uses the right ports.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where should a beginner go next?

Install Docker using the official installation instructions for your operating system; setup requirements differ by platform. Then follow Docker’s beginner path or hands-on workshop to practice starting containers, writing a Dockerfile, and building an image.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.