>Setting Up Docker Environment

Some basic docker commands to keep in mind:

docker images – shows your current pulled images

docker ps – shows current running containers

docker ps -a – shows recently opened/closed containers

*Containers can be pulled from Docker Hub.

Downloading Docker Engine

Normally when you are putting in docker commands, you refer to the desired image in the format: repository:tag.

For example, the ubuntu container would be pulled with ubuntu:latest

We can shorten this by assigning a custom name:

docker run –name container_name -it docker_image

The ‘-it’ option stands for interactive terminal and tells docker that we want a command line interface for our deployed machine.

I did this for all three of my containers:

  • kali -> attacker
  • ubuntu -> web_server
  • nginx -> reverse_proxy

Deploying the Nginx container is just a tad different as you have to specify the port it will be running through (80:80). Since I will be naming this reverse_proxy, the command looks like this:

docker run –name reverse_proxy -it -p 80:80 nginx:latest /bin/sh

After deploying all of these containers, you can use the ‘docker ps -a’ command to display the containers that are stopped:

Downloading Basic Packages (IP & Routing)

When deploying these containers, you may realize that basic commands (ip, ping, etc.) are not installed. In order to establish routing and basic connectivity between the containers, we must download some baseline packages:

  • apt install iproute2 -> ip routing
  • apt install iputils-ping -> ping utility
  • sudo apt install bash-completion -> bash shell
  • apk add openssl -> installs openSSL if not already installed
Establishing Basic Connectivity

Now all we need to do is open up separate terminal windows so we can see all three machines at the same time.

In one of the terminal windows, start one of the machines:

docker start container_name

This will start the specified container in the docker engine. You can use the command ‘docker ps’ to display your running containers, you should see the container you just deployed.

In order to log back into our containers with an interactive bash terminal, we will use the following:

docker exec -it container_name /bin/bash

Do this with each machine and use the ‘hostname -I’ command to get each IP address. You should notice that they all are very similar besides one octet.

To make sure the connectivity is routing between the machines, use the ‘ping ip’ command.

To stop the containers, simply use the ‘docker stop container_name‘ command and ‘docker ps’ to verify that there are no running containers.

Leave a Comment