Setting Up a Web Server for Scanning
In this step, we're going to set up a simple web server using Docker. Docker is a powerful platform that lets you package applications along with all their dependencies into standardized units called containers. These containers can be easily deployed and run on different systems. By setting up this web server, we'll have a target to scan with Nmap in the upcoming steps.
1. Navigating to the Working Directory
First, open a terminal window. The terminal is a command - line interface where you can enter commands to interact with your system. Once the terminal is open, you need to navigate to the project directory. This directory will serve as your working area for this lab.
To navigate to the project directory, use the cd
command. The cd
command stands for "change directory". Here's the command you need to run:
cd /home/labex/project
2. Creating a Dockerfile
A Dockerfile is a crucial part of building Docker images. It's a text document that contains a series of commands that Docker uses to build an image. In this case, we're going to create a Dockerfile for a simple web server based on Nginx, which is a popular web - server software.
To create a new file named Dockerfile
, we'll use the nano
text editor. nano
is a simple and user - friendly text editor that you can use directly in the terminal. Run the following command:
nano Dockerfile
After running this command, the nano
editor will open, and you can start adding content to the Dockerfile
. Add the following lines to the file:
## Use the nginx image as the base
FROM nginx
## Expose port 80
EXPOSE 80
The FROM
command tells Docker to use the nginx
image as the base for our new image. The EXPOSE
command indicates that the container will listen on port 80.
To save the file, press Ctrl+O
and then Enter
. To exit the editor, press Ctrl+X
.
3. Building the Docker Image
Now that we have our Dockerfile ready, we can build the Docker image. An image is like a blueprint that contains all the necessary files and configurations needed to run an application.
To build the image, run the following command:
docker build -t cyber-seed-portal .
In this command, the -t
flag is used to tag the image. We're tagging our image as "cyber - seed - portal". The .
at the end of the command tells Docker to use the current directory as the build context.
When you run this command, Docker will start the build process, and the output will look something like this:
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM nginx
latest: Pulling from library/nginx
a803e7c4b030: Pull complete
8b625c47d697: Pull complete
4d3239651a63: Pull complete
0f816efa513d: Pull complete
01d159b8db2f: Pull complete
5fb9a81470f3: Pull complete
Digest: sha256:32da30332506740a2f7c34d5dc70467b7dfe6c23451f6c66c84eeb3cdadab213
Status: Downloaded newer image for nginx:latest
---> 61395b4c586d
Step 2/2 : EXPOSE 80
---> Running in 1c2d5e2a8e7f
Removing intermediate container 1c2d5e2a8e7f
---> 7683abcf62b0
Successfully built 7683abcf62b0
Successfully tagged cyber-seed-portal:latest
4. Running the Docker Container
Once the image is built, we can create and run a container from it. A container is a running instance of an image.
To run a container, use the following command:
docker run --name cyber-seed-server -d -p 8080:80 cyber-seed-portal
Let's break down this command:
--name cyber-seed-server
: This gives the container the name "cyber - seed - server". Naming the container makes it easier to manage and identify.
-d
: This runs the container in detached mode, which means the container will run in the background, and you can continue using the terminal for other tasks.
-p 8080:80
: This maps port 8080 of your machine to port 80 of the container. So, when you access port 8080 on your machine, it will be redirected to port 80 inside the container.
cyber-seed-portal
: This specifies the image that the container will be based on.
When you run this command, the output will be a container ID, something like:
3a7b1a23c3c5d17b3e4b3e5e6f7g8h9i
You've now successfully set up a web server running in a Docker container. You can access this server at http://localhost:8080. This server will be the target for your Nmap scans in the next steps.