This post is part of a series of a simple networking scanning tool named PortScraper. I will explain how to embed the application into Docker image and how to prepare the setup (PortScraper + MariaDB) with docker-compose.

Port Scraper

If you want to follow the next steps you will need Git, Docker and Docker-compose installed. Lets begin, open a terminal and navigate to the directory where you want to clone the project and clone the project:
git clone https://github.com/ddavidmelo/port_scraper.git

After cloning the project, you can start playing around with Docker. To run a docker application is necessary to build a Docker image from a Dockerfile like this one from the project that you cloned:

DockerfileDockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
FROM    golang:1.19-alpine

ENV     PROJECT_PATH=/port_scraper

RUN     mkdir -p $PROJECT_PATH

COPY    .  $PROJECT_PATH
WORKDIR $PROJECT_PATH

RUN     go mod download
RUN     go build -o /port_scraper .
RUN     chmod +x /port_scraper 

CMD     [ "./port_scraper" ]

Since this project depends on a database to run, it will be easier to use Docker Compose. Docker Compose is a utility that allows you to set up and run multiple Docker containers as a single application. It allows you to create a configuration file in YAML format that defines the services your application requires. You can then use a single command to bring all of those services up and running at once, based on the configuration you’ve provided. So take a look at this docker-compose.yml:

docker-composedocker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
version: "3"

services:
  port_scraper:
    container_name: "port_scraper"
    build: .
    depends_on:
      - mariadb
    volumes:
      - ./config/:/port_scraper/config
  mariadb:
    container_name: "mariadb"
    image: mariadb
    restart: always
    ports:
      - 127.0.0.1:3306:3306
    volumes:
      - ./dbmaria:/config/databases/
    environment:
      - MARIADB_ROOT_PASSWORD=root

After running docker-compose up (or make up) a config.toml file will be created in the config folder and you can change the file_path to a different one (like this geolite2-city-ipv4.csv.gz.) or other parameters. I hope this tutorial helped everybody to get started with the port scraper application or to apply this concepts in other projects.