Docker
For a basic introduction to docker please refer to the official documentation
Structure
The directory docker_compose_dir contains the docker-compose.yaml that manages the project.
Each Unit of the project is contained within a docker container.
Containers:
- mysql_db
Central data storage of the project - backup
Periodically creates a backup of the mysql container - python_scraper
Fetches firmware images from vendor websites - scheduler
Periodically run scraper - frontend
Website for the Firmware_vault project - api_scheduler
Handles job scheduling for the firmware analysis - executor
Handles the execution of scheduled jobs - redis
Stores the job queue - binwalk (github Repository)
(Analysis Tool) Unpacks the downloaded firmware images - cve-bin-tool (pip Package)
(Analysis Tool) Finds known vulnerabilities in software - firmwalker
(Analysis Tool) Helps find things of interest, e.g. passwords, in mounted firmware images
Develop with docker watch
The file docker_compose_dir/compose.dev.yaml contains watch statements that enable quicker
development.
To include the watch statements use this command:
docker compose -f docker-compose.yaml -f compose.dev.yaml up --watch
The default Compose configuration is intended for local builds. If
IMAGE_PREFIX, APP_VERSION, and PULL_POLICY are not set, project images
use local names such as frontend:latest and are built from the checked-out
Dockerfiles. The base image also uses pull_policy: never, so local Compose
does not unexpectedly replace the locally built base image with a registry
image.
The same Compose file supports pull-based deployment through these variables:
IMAGE_PREFIX=hub.informatik.hs-augsburg.de/firmware-analysis/firmware_vault/
APP_VERSION=<commit-sha>
PULL_POLICY=always
Those values select versioned registry images. Deployment must pull them before
starting the stack and use docker compose up --no-build; local development
should leave the variables unset and continue using docker compose up -d --build.
Upon changes in files that are included in the compose.dev.yaml, the files get synced into
the container. There are three available settings:
- sync
The file gets synced into the container, - sync+restart
The file gets synced into the container. The container is then restarted, - rebuild
Upon changes on the file, the container will be rebuilt.
This removes the need for manual container restarts during development.
Container logs
By default Docker keeps the logs of a container forever (the json-file log driver has no size
limit). With the extractor and executor running for a few months, this filled about 500 GB on a
development machine.
All services in docker_compose_dir/docker-compose.yaml therefore use a shared logging
configuration (x-logging at the top of the file) that rotates the logs:
./configure option | Variable in .env | Default | Meaning |
|---|---|---|---|
--docker_log_max_size | DOCKER_LOG_MAX_SIZE | 50m | maximum size of one log file per container |
--docker_log_max_file | DOCKER_LOG_MAX_FILE | 3 | number of log files kept per container |
With the defaults every container keeps at most 3 × 50 MB = 150 MB of logs (about 2.2 GB for all 15 services); older lines are deleted automatically.
Set the limits with ./configure, which writes them to docker_compose_dir/.env. Either answer
the two questions during the interactive setup, or pass them as arguments (all other settings are
asked as usual):
./configure --docker_log_max_size=100m --docker_log_max_file=5
Do not only edit docker_compose_dir/.env by hand: ./configure rewrites the whole file and
would reset the values to the defaults. If the variables are missing in .env, the defaults
from docker-compose.yaml apply.
The settings only apply to newly created containers. After changing them, recreate the
containers with docker compose up -d --force-recreate. docker logs <container> only shows
the lines that are still kept.
When adding a new service, add logging: *default-logging to it.
To check the current size of all container logs (Linux host):
sudo du -sh /var/lib/docker/containers/*/*-json.log
Debugging Docker Problems
(Please note the Docker compose can take up to 20 minutes to build fresh)
While Docker has a bunch of advantages, it can be incredibly frustrating to debug. Here are some issues we encountered and how we fixed them.
Volumes are unable to find their folders
After calling "docker compose up," you might get an error like this:
Error response from daemon:
error while mounting volume 'volume path in container/_data':
failed to mount local volume: mount *path to the project*/docker_compose_dir/volumes/*one
of the volumes*: volume path in container/_data, flags: 0x1000: no such file or directory
This happens if you move the project directory to a different location after starting the docker environment at least once. Docker saves the volumes with absolute paths and does not update these if you move the project folder, therefore you need to delete the volumes and recreate them.
How to fix:
This command will delete all volumes from Docker so they can be rebuilt: !! If you have volumes from other projects, they will also be deleted !!
docker volume rm $(docker volume ls -q)
You can find the names of all volumes in the docker_compose_dir/docker-compose.yaml.
To remove a specific volume, e.g. backup use this command:
docker volume rm docker_compose_dir_backup
This will only work if the volumes are not used by a container. If the volume is still in use, you have to delete the container currently using the volume
My SQL DB container is in a restarting loop
This is probably caused because the mysql_data volume is not empty (and the data in it conflicts with the init.sql).
How to fix: Delete the contents of the /docker_compose_dir/volumes/mysql_data folder (hint: MySQL also creates hidden files).
If this does not work, also try to delete the volumes from Docker (so it can be rebuilt cleanly):
docker volume rm mysql_data
Clear everything from Docker
Stop all running containers
docker stop $(docker ps -aq)
Remove all containers
docker rm $(docker ps -aq)
Remove all images
docker rmi $(docker images -q)
Remove all volumes
docker volume rm $(docker volume ls -q)
Remove all networks (excluding the default ones)
docker network rm $(docker network ls | grep -v "bridge\|host\|none" | awk '/ / { print $1 }')
Remove Docker build cache
docker builder prune -a