Skip to content

Latest commit

 

History

159 Commits

Folders and files

Repository files navigation

docker-dev-scripts

CI License: MIT Docker Debian 13.8 Bash Environments ShellCheck Conventional Commits

One-command Docker development environments: 19 environments for languages, mobile apps, games and the web, and 3 monitoring labs. Each lives in its own directory and is set up with ./project.sh start and removed with ./project.sh clean, so nothing but Docker needs to be installed on the host.

Features

  • Fully automated setup. ./project.sh start builds or pulls the images, generates docker-compose.yml and a working example project, installs the dependencies and runs it.
  • Nothing overwritten. Existing project files are kept, so you can develop your own project in place of the example and run ./project.sh start again.
  • Files owned by you. On GNU/Linux the containers run with your user and group id, and with your other groups and those of the GPU, KVM and sound devices.
  • Simple cleanup. ./project.sh clean lists everything in the environment's directory and removes it once you confirm.
  • GPU, display and sound. The graphical environments use the host's GPU (Intel, AMD, NVIDIA), X server and PipeWire/PulseAudio.
  • Monitoring labs. Prometheus, VictoriaMetrics and Zabbix watch a WordPress site, with exporters and Grafana.

Quick start

git clone https://github.com/aljazmc/docker-dev-scripts.git
cd docker-dev-scripts/node-dev
./project.sh start
./project.sh clean

Requirements

Requirement Notes
GNU/Linux with bash the environments are developed and tested on it. android-dev, bevy-dev, godot-dev, heaps-dev, ocaml-dev and reactnative-dev require it; the others only use bash and Docker
Docker with the compose plugin, installed and running
/dev/kvm and mate-terminal for android-dev and reactnative-dev (hardware virtualization)

Environments

Languages

Environment Stack ./project.sh start
gcc-dev C with GCC compiles and runs main.c
go-dev Go builds and runs main.go
haskell-dev Haskell with Stack compiles and runs helloworld.hs
java-dev Java (OpenJDK) compiles and runs HelloWorld.java
node-dev Node.js with Yarn creates package.json or installs its dependencies
ocaml-dev OCaml with opam and Dune sets up opam, builds and runs a Dune project
python-dev Python compiles and runs hello.py
rust-dev Rust installs the stable toolchain, compiles and runs hello.rs

Mobile

Environment Stack ./project.sh start
android-dev Android, Kotlin and Jetpack Compose downloads the SDK, builds the app and runs it in the emulator
reactnative-dev React Native for Android downloads the SDK, creates the app and runs it in the emulator

Games

Environment Stack ./project.sh start
bevy-dev Bevy (Rust) builds and runs a game; bundles for Linux and Windows
godot-dev Godot 4.7 with C# builds and runs a game; bundles for Linux, Windows and macOS
heaps-dev Heaps on HashLink (Haxe) builds and runs a game; bundles for Linux, Windows and macOS

Web

Environment Stack ./project.sh start
django-dev Django, PostgreSQL, Adminer generates a project, migrates, starts the server
drupal-dev Drupal 11, MariaDB, phpMyAdmin generates a Composer project, installs Drupal with Drush
joomla-dev Joomla, MariaDB, phpMyAdmin installs Joomla, adds PHPUnit and PHP_CodeSniffer
lamp-dev Apache, MariaDB, PHP 8.4, phpMyAdmin generates a tested PHP project, starts the services
laravel-dev Laravel, MariaDB, phpMyAdmin, Node.js generates a project, migrates, builds the assets
wordpress-dev WordPress, MariaDB, PHP 8.4, Node.js, phpMyAdmin sets up theme development, installs WordPress

Monitoring labs

Environment Stack ./project.sh start
prometheus-lab WordPress, Prometheus, exporters, Grafana monitors WordPress, Apache and MariaDB
victoriametrics-lab WordPress, VictoriaMetrics, exporters, Grafana monitors WordPress, Apache and MariaDB
zabbix-lab WordPress, Zabbix, Grafana monitors WordPress, Apache and MariaDB

The web environments and labs publish their services on localhost (port 80 for the site, 8080 for the database tool, 3000 for Grafana), so only one of them runs at a time, unless the others get ports of their own with PORT_BASE, e.g. PORT_BASE=9000 ./project.sh start for 9000, 9001 and so on. Each environment's README.md lists its URLs, credentials and further commands.

Structure

Each environment directory contains:

  • project.sh - generates docker-compose.yml and the project files, then starts the environment. The functions it can run are its arguments: start and clean everywhere, and e.g. bundleforlinux, autoload or traffic where the README mentions them.
  • Dockerfile - builds the development image, mostly from debian:13.8. joomla-dev, wordpress-dev and the labs use prebuilt images only.
  • README.md - what start does, the generated files, the services and the license of the main project

Everything else in an environment directory is generated and ignored by git.

Caution

./project.sh clean is meant for developing project.sh itself: it removes all files in the environment directory except Dockerfile, project.sh and README.md, and runs docker compose down -v --rmi all --remove-orphans, which removes the environment's containers, networks, volumes (including databases) and images. Other Docker projects are left untouched. It lists the files and asks first, and ./project.sh clean --force does not ask. Your own files are removed too, so when you develop your own project in an environment, change clean first!

Troubleshooting

Starting

Compose plugin is not installed, or docker: unknown command: docker compose. Install the Compose plugin and check it with docker compose version. The old docker-compose command is not enough.

permission denied while trying to connect to the docker API. Your user may not use Docker. Add it to the docker group and log in again, see Docker's post-installation steps.

failed to connect to the docker API. Docker is not running. Start it, e.g. with sudo systemctl start docker.

Usage: ./project.sh {start|clean}. The function is missing or misspelled. The usage lists the ones of the environment.

start stopped halfway. It ends at the first error, which is the last message. Solve that and run ./project.sh start again. It keeps existing files, so some steps of the first run may be left out, e.g. the packages that are installed along with a new composer.json, or the SDK once sdk/cmdline-tools/latest exists. Remove those files, or everything with ./project.sh clean, to run the steps again.

Building the image takes long, or fails while it downloads packages. The Debian packages come from snapshot.debian.org, which is slower than the usual mirrors. Downloads are tried again up to ten times; run ./project.sh start once more if that is not enough.

A Debian package is outdated. All of them are as of the day in SNAPSHOT in the Dockerfile, security updates included. Raise the day there and rebuild the image with docker compose build.

Ports

Bind for 0.0.0.0:80 failed: port is already allocated. Another environment or program uses the port. Stop the other environment with docker compose stop in its directory, or start this one on ports of its own:

PORT_BASE=9000 ./project.sh start

PORT_BASE must be a number from 1024 to 65534. Choose one in that range, or up to 65532 for the labs, which use four ports in a row.

docker-compose.yml was made with the default ports, not with PORT_BASE=9000 (or with another PORT_BASE). The ports are set when docker-compose.yml is generated. Leave PORT_BASE out to go on with the ones it has. ./project.sh clean lets you start over with others, but removes your files and databases too.

Cleaning

clean removes the files of the current directory, so run it in the one of project.sh. Change to the directory of the environment first; nothing was removed.

Nothing removed: run ./project.sh clean --force. Without a terminal, as in a script, clean can't ask you. --force removes everything without asking.

An image of another project is gone after clean. It removes all images the environment uses, also shared ones such as mariadb or wordpress. Docker pulls them again when they are needed, but images you built yourself have to be built again.

Graphics, sound and the emulator

services.bevy.devices must be a array (or godot, heaps, ocaml). The host has neither /dev/dri nor /dev/snd, as in many virtual machines and over SSH on servers. Delete the line devices: of that service from docker-compose.yml. A window still needs an X server.

NVIDIA GPU found, but NVIDIA Container Toolkit is not installed. Only a warning: the container uses another GPU or software rendering. Install the toolkit, remove docker-compose.yml and run ./project.sh start again to use it.

error gathering device information while adding custom device "/dev/kvm". android-dev and reactnative-dev need hardware virtualization: enable it in the BIOS or UEFI of the host, or nested virtualization in a virtual machine.

Install mate-terminal to be able to start this development environment! android-dev and reactnative-dev run the emulator in it. On Debian and Ubuntu install the mate-terminal package.

Single environments

Script runs only on GNU/Linux OS, or This script works only on GNU/Linux systems. bevy-dev, godot-dev, heaps-dev, ocaml-dev and reactnative-dev need it, with glibc: Alpine Linux does not count.

Joomla is not installed after 3 minutes. See what it is waiting for with docker compose logs joomla in joomla-dev.

Error: Library "core" not found in ocaml-dev. opam's packages are found in a login shell: docker compose run --rm ocaml bash -lc "cd helloworld && dune build".

Tests

bash tests/test_compose.sh
bash tests/test_clean.sh
bash tests/test_errors.sh
bash tests/test_ports.sh
shellcheck */project.sh tests/*.sh

tests/test_compose.sh runs ./project.sh compose and composehack of every environment in a temporary directory, with docker replaced by a stand-in, and checks that docker-compose.yml is written, gets your user and group id and your other groups once, and, if Docker is installed, is accepted by docker compose config. tests/test_clean.sh checks, in the same way, that clean removes nothing unless you confirm or use --force, and tests/test_errors.sh that every failure, e.g. of any docker call of start, ends it with a message on stderr and an exit code other than 0. tests/test_ports.sh checks that PORT_BASE moves every published port. The lint workflow runs ShellCheck on every push and pull request.

License

The scripts are licensed under the MIT License. The environments download and run third-party software under its own licenses, which each environment's README.md lists.

Releases

Packages

Contributors

Languages