tools

Overview

Docker is an open-source platform for building, shipping, and running applications in isolated containers. It automates deployment using a layered filesystem and resource isolation. Docker is widely used in DevOps and penetration testing to create portable, reproducible environments.

Target / Context

Linux and cross-platform environments requiring isolated application deployment. Common in CTF and pentesting for file hosting servers, payload staging, and tool environments.


Installation

ℹ︎Installation Commands (Ubuntu):
sudo apt update -y
sudo apt install ca-certificates curl gnupg lsb-release -y
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update -y
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
sudo usermod -aG docker $USER

Test:

docker run hello-world

Basic Usage

ℹ︎Basic Usage:

Build an image from a Dockerfile in the current directory:

docker build -t <image_name> .

Run a container from an image:

docker run -p <host_port>:<container_port> -d <image_name>

List running containers:

docker ps

Flags & Options

ℹ︎Flags & Options:
FlagDescriptionExample
-tTag/name the imagedocker build -t myapp .
-pMap host port to container portdocker run -p 8080:80 myapp
-dRun container in detached (background) modedocker run -d myapp
-nName the containerdocker run —name mycontainer myapp
-vMount a volume for data persistencedocker run -v /host/path:/container/path myapp
-eSet environment variablesdocker run -e VAR=value myapp
—rmAutomatically remove container on stopdocker run —rm myapp

Common Use Cases

Build and Run a Container

ℹ︎Commands:
docker build -t fs_docker .
docker run -p 2222:22 -p 8080:80 -d fs_docker

Container Management

ℹ︎Commands:

List running containers

docker ps

List all containers including stopped

docker ps -a

Stop a running container

docker stop <container>

Start a stopped container

docker start <container>

Restart a container

docker restart <container>

Remove a container

docker rm <container>

Remove an image

docker rmi <image>

View container output logs

docker logs <container>

File Hosting Server (Dockerfile Example)

For file transfer during assessments — SSH for scp uploads, Apache for wget/curl downloads.

ℹ︎Dockerfile:
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y apache2 openssh-server && rm -rf /var/lib/apt/lists/*
RUN useradd -m docker-user && echo "docker-user:password" | chpasswd
RUN chown -R docker-user:docker-user /var/www/html /var/run/apache2 /var/log/apache2 /var/lock/apache2
RUN usermod -aG sudo docker-user && echo "docker-user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
EXPOSE 22 80
CMD service ssh start && /usr/sbin/apache2ctl -D FOREGROUND

Build:

docker build -t fs_docker .

Run:

docker run -p 2222:22 -p 8080:80 -d fs_docker


References / Images

  • Docker Hub: hub.docker.com
  • Docker documentation