Articles

Docker: images, containers and a clear runtime environment

From inconsistent development environments to Dockerfile, images, containers and Compose: an explanation of portability, isolation and virtual-machine boundaries.

Packaging and isolated runtime environments — conceptual cover
Generated conceptual illustration, not a product screen or research result.

The problem: an application is more than its code

Why can a program work on a developer's computer and fail on another? The code may be identical while the language version, libraries or runtime settings differ. Docker starts with this problem: describe the application environment, build an image and create a container to run it.

For example, rather than manually installing Node.js and its dependencies each time, we record the build steps in a Dockerfile. We will distinguish those instructions from an image and a container, then try a small program.

Docker lets us describe an application environment and build an image from which containers can run. This reduces repeated manual installation, but runtime settings, storage, networking and security still need deliberate management. Docker overview

What are Docker and a container?

Docker is a platform for developing, shipping and running applications using containers. Docker Engine is open-source; that does not give every Docker-branded product or commercial plan identical licence terms.

A container is a relatively isolated runtime environment for application processes and their required files. Isolation does not remove its dependency on a kernel and runtime, or make it immune to misconfiguration and resource exhaustion. Docker Engine, Docker Desktop terms, Containers, Engine security

An image is not a container

TermMeaning
DockerfileInstructions for building an image
ImageLayered files and configuration needed for execution
ContainerAn instance created from an image, with settings and a writable layer
RegistryA public or private image distribution store

Several containers can use one image. Changing a container's files does not change that original image. Data that must survive container removal should not depend only on its temporary writable layer. Container images

For Node.js and MongoDB, the application and database need not be packed into one image. They can be separate services with appropriate networking and persistent storage. Compose application model

Building, running and sharing

The basic sequence is application code, Dockerfile instructions, image build, then container creation. An image may be pushed to a registry and pulled elsewhere. Docker Hub is one registry, not the only choice. A public image is distinct from a private repository requiring access permission. Dockerfile overview

The commands build, run, push and pull have different jobs. Building does not automatically run the application; pushing does not automatically deploy a complete service. Keep keys and private environment files out of the build context and image layers. Build secrets

Docker Compose

Compose describes a multi-service application in compose.yaml: services, images, networks, persistent storage and settings. The PHP and MySQL example illustrates separation of application and data services. Backups, permissions and data initialisation remain separate responsibilities. How Compose works

Benefits with boundaries

  • Dependency management: an image gives a defined environment, but versions and updates still need control; tags can change.
  • Portability: the operating platform, CPU architecture and runtime must be compatible. Not every image runs on every device.
  • Development and deployment: repeated setup can be reduced, but no fixed startup time or speed gain is guaranteed.
  • Service separation: multiple versions can coexist when published ports, resources and storage are configured correctly.

Reproducibility requires dependency control and image identity as well as an update plan. Pinning versions does not remove the need to address vulnerabilities. Build best practices

Containers and virtual machines

A virtual machine runs a guest operating system with its own kernel. Linux containers share the kernel of the Linux environment that runs them, rather than carrying independent kernels. On Windows or macOS, Docker Desktop normally runs Linux containers in a virtualised environment; they do not always share the physical host operating system's kernel directly. Containers and VMs, Desktop virtualisation

Container overhead can be lower than a complete guest OS per application, but the workload and configuration determine the actual comparison. Containers and VMs are often used together.

An image is stored; a container is run
Container imageStored, read-only layers
Application filesDependencies and language runtimeBase system files
Create and run
First containerIsolated process + writable layer
Second container from the same image
Container runtimeManages container creation, execution and isolation.
Container host kernel
How is a virtual machine different?
ContainerIsolated process + writable layerContainer runtimeContainer host kernel
Virtual machineApplication + guest OS with its own kernelHypervisorHost infrastructure

Compatible containers share their host kernel. That host may itself be a virtual machine, as when Linux containers run on Docker Desktop.

An image packages application files and dependencies. The runtime creates isolated containers from it, each with its own state and writable layer.

Concept reference: Docker image and container documentation

A practical example: a small program and its image

Use a separate experiment directory containing no secrets or project files, then create hello.mjs:

console.log('Hello from the teaching example.');

Create Dockerfile alongside it:

FROM node:24-alpine
WORKDIR /app
COPY --chown=node:node hello.mjs ./
USER node
CMD ["node", "hello.mjs"]

With Docker available locally, the following can be tried:

docker build -t portfolio-docker-demo:local .
docker run --rm --network none --read-only --cap-drop=ALL --security-opt=no-new-privileges portfolio-docker-demo:local

The expected output is Hello from the teaching example., after which the program stops. The run command publishes no port and mounts no host directory; it disables container networking and makes its filesystem read-only. The build may download a base image and use disk space; it is not required to read this article.

This example was built and run on 11 October 2026 on Linux/amd64, using Docker 29.8.2 and the official node:24-alpine image. It printed Hello from the teaching example. and exited with code 0. The test covered this example only, not Compose, databases or production readiness. Official Node.js image, Dockerfile reference, Runtime options

Base-image digest at the time of testing: sha256:ebfe2f90462722a7a4de65e91990e97fe0d401c70e0e762c5b53302f905ec1c1. The node:24-alpine tag can change; verify the image again before repeating the experiment.

Relation to projects

The Rawaj case study explores application responsibilities, data and order flows. It offers complementary reading on separation of concerns in a software project, independent of its deployment tools.

References

Help improve this content

Suggest a correction or edit

Your contribution is private and used to review and improve this content. The Privacy Policy explains how data is processed and retained and how to request deletion. Read the Privacy Policy and Terms of Use.