Skip to content
Maksym Zaporozhets edited this page Apr 27, 2023 · 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.

IMPORTANT! This documentation is for the 3.1.0-development branch, which will be released soon. The code is already stable enough, so you can use it.

Teaser: Install Magento with one command

php bin/dockerizer magento:setup 2.4.5-p2

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 ~/.bash_aliases (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.
cd "${DOCKERIZER_PROJECTS_ROOT_DIR}"
mkdir ./traefik-reverse-proxy/
cd ./traefik-reverse-proxy/
php ~/misc/apps/dockerizer_for_php/bin/dockerizer composition:build-from-template --template=traefik
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.

Generating compositions

php ~/misc/apps/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 ./.dockierizer/my-awesome-project.com-prod/ directory (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.
  • Generates self-signed SSL certificate for development (thanks to mkcert)
  • Modifies the /etc/hosts file.
  • Populates 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.

We're working on adding more documentation here. Meanwhile, you can run the tool and check commands help.

Dockerizer limitations

  1. MySQL password must not contain single quotes ('), double quotes ("), or backslash (\). Unfortunately, entrypoint scripts in different MySQL images use password environment variable in a different way. It is almost impossible to make it work with all of them. Thus, we decided to limit the password to a string without quotes. Other special characters are allowed.
  2. Remember that $ character in the MySQL password becomes $$ in the YAML files. Thus, $$$ becomes $$$$$$ in your docker compose file. This is a limitation of the YAML format.
Clone this wiki locally