Docker for Beginners: Run Your First Container

Docker and Containers 2 min readUpdated Oct 29, 2026
3 views0 comments

Docker packages an application together with everything it needs, so it runs the same on your laptop, a test server and production. This guide takes you from zero to a running container and your first custom image. You need Docker installed (Docker Desktop on Windows and macOS, or Docker Engine on Linux).

Images and containers in one minute

  • An image is a read-only template: the application plus its files and settings.
  • A container is a running instance of an image. You can start many containers from one image.

Think of the image as a recipe and the container as the dish.

Step 1: Check that it works

docker run hello-world

Docker downloads a tiny image, runs it and prints a welcome message. If you see it, the installation is fine.

Step 2: Run a real web server

docker run -d --name web -p 8080:80 nginx
  • -d runs it in the background.
  • --name web gives the container a friendly name.
  • -p 8080:80 maps port 8080 on your machine to port 80 inside the container.

Open http://localhost:8080 in your browser and you will see the nginx welcome page.

Step 3: Look inside

docker ps                    # running containers
docker logs web              # what nginx printed
docker exec -it web sh       # open a shell inside the container
exit                         # leave the shell

Step 4: Serve your own files

A volume shares a folder from your machine with the container. Create a folder with an index.html, then:

docker rm -f web
docker run -d --name web -p 8080:80 -v "$PWD":/usr/share/nginx/html:ro nginx

Refresh the page: it now shows your file. On Windows PowerShell use ${PWD} instead of "$PWD".

Step 5: Build your own image

Create a file named Dockerfile next to your index.html:

FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html

Then build and run it:

docker build -t my-site .
docker run -d --name my-site -p 8081:80 my-site

Your site is now a self-contained image you can push to a registry and run anywhere.

Clean up

docker stop web my-site
docker rm web my-site
docker system prune          # removes unused containers, networks and dangling images

Data written inside a container is lost when the container is removed. Anything that must survive (databases, uploads) belongs in a volume.

Where to go next

  • Learn Docker Compose to run several containers (app, database, cache) from one file.
  • Use small base images such as alpine to keep images fast to download.
  • Never bake passwords into an image. Pass them at run time with -e or a secrets file.
Did you find this helpful?Tap the heart to let us know. It takes one second and no account.

Leave a Comment

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

Bigland Network IT

Practical tutorials for people who run, build and fix things: operating systems, databases, development, networking and security.

Topics

More

Site

© 2026 Bigland Network. All rights reserved.Always test commands on a non-production system first.
Scroll to Top