Skip to content
Maksym Zaporozhets edited this page Jan 7, 2024 · 13 revisions

Welcome to the Dockerizer Wiki!

This tool helps quickly generate Docker compositions for your projects. It can do exciting things like importing MySQL dumps or generating MySQL Docker images from database dumps and metadata. Started as a project to help with Magento & PHP development, it transforms into the language-agnostic Docker compose helper tool.

Unlike other tools, the main idea of the Dockerizer tool is transforming application system requirements into docker-compose.yaml files. Developers have only a limited set of available preconfigured services for every application. This makes generating and sharing correct development environments much easier without paying for cloud solutions.

We also know that developers may have multiple projects, or they work on updating the app on the development server while production has different software versions. You can easily generate a few sets of configurations that are managed independently.

Teaser: Install Magento with one command

php bin/dockerizer magento:setup 2.4.6

You will interactively enter all required options or confirm the default ones. All Docker-related files will be available inside your project without committing them. See the documentation for the magento:setup command for more details about the command options and what it does.

Configuring the tool

  1. Add the following environment variables to your ~/.bash_aliases or other shell configuration file:
# Where are your projects located?
export DOCKERIZER_PROJECTS_ROOT_DIR=${HOME}/misc/apps/
# Where to put SSL certificates for your applications?
export DOCKERIZER_SSL_CERTIFICATES_DIR=${HOME}/misc/certs/

Restart your shell or run source ~/.bashrc (or another command for your shell) to apply the changes.

  1. Ensure that ports 80 and 443 are free on your machine. They will be used by the Traefik reverse-proxy to serve your applications.
  2. Add auth.json to dockerizer_for_php/app/config/ directory. Required for Magento-related commands.
  3. Install Traefik reverse-proxy php bin/dockerizer traefik:install (check this article for MacOS and Docker Desktop support: MacOS and Docker Desktop support):
cd "${DOCKERIZER_PROJECTS_ROOT_DIR}"
mkdir ./traefik-reverse-proxy/
cd ./traefik-reverse-proxy/
# Use `--required-services=traefik_bridge_network` for MacOS and Docker Desktop
php "${DOCKERIZER_PROJECTS_ROOT_DIR}dockerizer_for_php/bin/dockerizer" composition:build-from-template \
    --template=traefik --required-services=traefik_host_network
mv ./.dockerizer/reverse-proxy/* ./
rm -rf ./.dockerizer/
# Configure DOCKERIZER_TRAEFIK_SSL_CONFIGURATION_FILE
printf '\nDOCKERIZER_TRAEFIK_SSL_CONFIGURATION_FILE=%straefik-reverse-proxy/traefik/configuration/certificates.toml' "${DOCKERIZER_PROJECTS_ROOT_DIR}" >> ${DOCKERIZER_PROJECTS_ROOT_DIR}dockerizer_for_php/.env.local
docker-compose up -d

Visit Traefik Dashboard to ensure that it works.

  1. Optionally, make the file /etc/hosts writable by your user: sudo setfacl -m "${USER}":rw /etc/hosts. This will allow the tool to add domains to it without a need to enter password. Do this at your own responsibility.

Tell us if you think there should be installation command to make this process easier.

Use Ubuntu post-installation scripts to install a full set of PHP development tools including Dockerizer!

Generating Docker compositions

See full description here: composition:build-from-template

php "${DOCKERIZER_PROJECTS_ROOT_DIR}dockerizer_for_php/bin/dockerizer" composition:build-from-template \
    --domains='my-awesome-project.com www.my-awesome-project.com' \
    --template=magento_2.4.5_nginx_varnish_apache \
    --required-services=mariadb_10_4_persistent \
    --optional-services=redis_6_2

This command will:

  • Generate docker-compose.yaml file in the directory ./.dockierizer/my-awesome-project.com-prod/ (use the --with-environment=xxx option to change the environment name and directory name suffix).
  • Copy and modify Docker service configuration files: virtual host configurations, Varnish VCL file, MySQL configuration, etc.
  • Create a docker-compose-dev-tools.yaml in the same directory that extends the default file and adds tools like phpMyAdmin, MailHog, etc.
  • Generate self-signed SSL certificate for development (thanks to mkcert)
  • Modify the /etc/hosts file.
  • Populate Traefik reverse-proxy configuration file with the certificate information. We use it so that you don't have to worry about container ports and IPs.

After running this single command, you're ready to run the Docker composition that serves your app, or you can modify the generated files to fit your needs.

Traffic routing and containers isolation

The below schema shows how the network traffic is routed from the host machine to the containers and back.

Infrastructure schema

Dockerizer limitations

Pay attention to the Limitations page to avoid common issues.

System requirements

  • PHP 8.0.2, 8.1.x, 8.2.x, 8.3.x
  • PHP extensions: curl, json, pcntl, posix, simplexml, fileinfo, zip (see composer.json for the latest information)
  • Docker & docker compose. Tested with Docker version 20.10.21 and 24.0.7.
Clone this wiki locally