Docker Basics: Run Isolated Labs on Linux (Safely)


Want to run a vulnerable web app for practice, test a new tool, or spin up a database — without installing anything permanently on your system? Docker does exactly that. It packages an application and everything it needs into a container: a lightweight, isolated box that runs on your Linux machine and disappears when you’re done. Here’s how it works and how to use it safely.

What Is Docker, Really?

A container is not a virtual machine. A VM boots a whole operating system with its own kernel. A container shares your host’s kernel and only isolates the application and its files. That makes containers fast to start (seconds, not minutes) and light on resources — you can run dozens on a laptop.

Docker uses images (frozen snapshots of an application) and containers (running instances of an image). You pull an image from Docker Hub, run it, and you have a working app in an isolated sandbox.

Your First Container

Install Docker on Ubuntu or Debian:

sudo apt update && sudo apt install docker.io -y
sudo systemctl enable --now docker
sudo usermod -aG docker $USER # log out and back in for this to apply

Then run your first container:

docker run hello-world
docker run -d -p 8080:80 nginx # a web server on port 8080
docker ps # list running containers
docker stop <container-id> # stop it
docker rm <container-id> # delete it

That nginx container is a real web server, isolated from your host, reachable at http://localhost:8080.

Why Security Learners Love Docker

  • Disposable labs. Run OWASP Juice Shop, DVWA or a vulnerable app in a container, break it, delete it, start fresh in seconds.
  • No system pollution. Tools and their dependencies live inside the container, not on your host.
  • Repeatable setups. A Dockerfile records exactly how a lab was built — share it, and anyone can rebuild the same environment.

The Security Mistakes That Hurt

Docker is powerful, and the defaults can bite you:

  1. Never expose the Docker socket. The Docker daemon socket (/var/run/docker.sock) gives full control of the host. Mounting it inside a container is effectively giving that container root on your machine. Never do it outside a trusted lab.
  2. Don’t run containers as root unless you must. Use the –user flag or build images with a non-root user. A root process in a container that escapes is a root process on your host.
  3. Don’t run random images from Docker Hub. Anyone can publish an image. Stick to official images and images from publishers you trust, and check the image’s Dockerfile and download counts first.
  4. Keep images updated. Old images carry old vulnerabilities. Rebuild regularly with docker pull and docker image prune.
  5. Limit resources and network access. Use –memory and –cpus limits, and don’t publish ports you don’t need (-p 127.0.0.1:8080:80 binds to localhost only).

Handy Commands to Remember

docker images # list downloaded images
docker logs <container> # read a container's output
docker exec -it <container> bash # get a shell inside a running container
docker compose up -d # start a multi-container app from a compose file

Level Up

  • Learn Docker Compose to define multi-container labs in a single YAML file.
  • Try Portainer for a web dashboard to manage your containers.
  • Study container escape vulnerabilities to understand why the rules above exist.

Docker turns your Linux machine into a lab bench: spin up anything, break it safely, throw it away. Just respect the isolation — it’s a sandbox, not a vault.

Comments

Popular Posts