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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Docker packages an application and its dependencies into an image, then runs that image as an isolated container. Think of the image as a reusable, read-only template and the container as a running instance with its own writable layer. Docker provides tools to build, share, and run these packages.

What is Docker?

Docker is a platform for developing, shipping, and running applications. Its tools let you build an image, distribute it through a registry, and start containers from it. Docker’s beginner documentation introduces this workflow.

Containerization packages an application and the dependencies it needs into an isolated environment. A container is not a full virtual machine: it runs as an isolated process on a host. This packaging can make deployments 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. You can start more than one container from the same image.

A container has a writable layer for changes made while it runs. That layer is not a reliable place for data you need to keep: removing the container removes its unpersisted changes. Use persistent storage, such as a volume, for data that should survive the container’s lifecycle.

What is a Docker image?

An image is a read-only template made up of layers and configuration needed to run a container. A registry stores and distributes images; Docker Hub is a public registry, and Docker’s documented default setup uses it for image lookups. The official guide explains what an image is.

Concept Image Container
Purpose Reusable template for creating containers Runnable instance of an image
Changes Read-only layers Has a writable layer for runtime changes
Lifecycle Can be used to start multiple containers Can be stopped and removed; unpersisted changes disappear on removal

How do I run a Docker container?

Install Docker using the official installation instructions for your operating system. The steps and requirements differ by platform.

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

These commands use the NGINX image as a simple example. Run them in a terminal where Docker is available:

# Download the image explicitly
docker pull nginx

# Start it in the background; make container port 80 available at 127.0.0.1:8080
docker run -d --name web -p 127.0.0.1:8080:80 nginx

# Open http://127.0.0.1:8080 in a browser

# List running containers
docker ps

# Include stopped containers
docker ps -a

# See the container's logs
docker logs web

# Stop and remove it
docker stop web
docker rm web

docker pull fetches an image. docker run creates and starts a container; if the image is not already local, Docker may pull it automatically. The -d option runs the container in the background, and --name web gives it a convenient name.

The -p host_port:container_port option publishes a container port to the host. Here, the host listens on port 8080 and forwards traffic to port 80 in the container. Binding to 127.0.0.1 limits this example to the local machine. If you omit a host IP, Docker’s current documentation says the published port binds on all interfaces by default. Ports are not published to the host automatically.

docker ps lists running containers; docker ps -a also shows stopped ones. docker logs displays a container’s output. Stopping a container does not remove it; docker rm removes the stopped container.

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

How do I build a Docker image?

Write a file named Dockerfile in your project directory. It contains instructions for the image builder. A small example looks like this:

FROM nginx:alpine
WORKDIR /usr/share/nginx/html
COPY . .
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
  • FROM selects a base image.
  • WORKDIR sets the working directory for later instructions.
  • COPY copies files from the build context into the image.
  • EXPOSE documents the port the service listens on; it does not publish that port to the host.
  • CMD sets the default command used when a container starts.

These instructions and their use are covered in Docker’s Dockerfile reference. This example expects suitable website files in the project directory; the Dockerfile alone does not create application content.

Build and run the image from that directory:

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

docker build executes the Dockerfile instructions. The -t my-app:1.0 option assigns the image a readable name and tag. The final . is the build context: the current directory and the files the builder can use. docker run starts a container from the image, publishes its service locally, and --rm removes the container when it exits.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which Docker commands should a beginner know?

Command What it does
docker pull IMAGE Fetches an image from a registry.
docker run IMAGE Creates and starts a container from an image; Docker may pull the image if it is not local.
docker ps Lists running containers.
docker ps -a Lists running and stopped containers.
docker logs NAME_OR_ID Shows a container’s logs.
docker stop NAME_OR_ID Stops a running container.
docker rm NAME_OR_ID Removes a stopped container.
docker build -t NAME:TAG . Builds an image from the Dockerfile and current-directory build context, then tags it.

What should I learn next?

Docker’s getting-started path and hands-on workshop cover first containers, Dockerfiles, image builds, and optional image publication. Once the commands above make sense, those guided exercises are a practical next step.

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

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.