Docker Compose¶
For a quick and easy way to get started developing on OpenMage, you can use the following one-line command to install OpenMage with Docker Compose.
Info
If you prefer a more robust development environment, consider using DDEV.
This will clone the OpenMage repository, create a new Docker Compose product named openmage and run the installation. Visit http://openmage-7f000001.nip.io/ and start coding!
Info
If you want to install the Magento Sample Data run the command with the environment variable SAMPLE_DATA=1 like so:
git clone https://github.com/OpenMage/magento-lts.git && cd magento-lts && SAMPLE_DATA=1 dev/openmage/install.sh
Prerequisites¶
- Install Docker
- Port 80 on your host must be unused. See Environment Variables below if you need to use another port.
Tips¶
See colinmollenhour/docker-openmage for more information on the containers used in this setup, but here are some quick tips:
- You can start the Cron task using
docker compose up -d cron. - The
cliservice contains many useful tools likecomposer,magerun,modman,mageconfigsyncand more. - Xdebug is enabled using
remote_connect_back=1withidekey=phpstorm. Customize this in.envif needed as described below.
Here are some common commands you may wish to try (from the dev/openmage directory):
$ docker compose run --rm -u $(id -u):$(id -g) cli composer show
$ docker compose run --rm -u $(id -u):$(id -g) cli bash
$ docker compose run --rm cli magerun sys:check
$ docker compose run --rm cli magerun cache:clean
$ docker compose run --rm cli magerun db:console
$ docker compose exec mysql mysql
- The
clicontainer runs aswww-databy default so use-u $(id -u):$(id -g)with composer so that the container will create/modify files with your user permissions to avoid file permission errors in your IDE. - Always use
run --rmwith theclicontainer to avoid creating lots of orphan containers.
Environment Variables¶
You can override some defaults using environment variables defined in a file (that you must create) at dev/openmage/.env.
XDEBUG_CONFIG=...- Override the default Xdebug configurationHOST_NAME=your-preferred-hostnameopenmage-7f000001.nip.iois used by default to resolve to127.0.0.1. See nip.io for more info.
HOST_PORT=888880is used by default
ADMIN_HOST_NAMEopenmage-admin-7f000001.nip.iois used by default to resolve to127.0.0.1. See nip.io for more info.
ADMIN_HOST_PORT81is used by default to avoid conflicts with the front-end port
ADMIN_EMAILADMIN_USERNAMEADMIN_PASSWORD(must be 14 characters or more)ADMIN_FIRSTNAMEADMIN_LASTNAMEMAGE_IS_DEVELOPER_MODE1is used by default, set to0to disable
CURRENCYUSDis used by default
LOCALEen-USis used by default
TIMEZONEAmerica/New_Yorkis used by default
MYSQL_PORT3306is used by default
PM_MAX_CHILDREN- Tune to your environment and needs - see PHP-FPM configurationPM_START_SERVERSPM_MIN_SPARE_SERVERSPM_MAX_SPARE_SERVERS
Uninstalling / Starting Over¶
If you want to start fresh, wipe out your installation with the following command (from the dev/openmage directory):
Production¶
You can easily have a multi-store SSL-protected environment using Docker with the docker-compose-production.yml file.
Features included out of the box:
- Free and automatic SSL provided by Caddy
- Separate domains for front-end and admin sites
- Examples included for redirects,
BasicAuth, multi-store routing - Easily add routes to your other sites
- Root static assets (e.g.
robots.txt) in a separate directory for each store view
Warning
Do not try to run a development environment and a production environment from the same working copy!
If using OpenMage as a composer dependency, to avoid files being overwritten by composer upon updating OpenMage, it is recommended to copy the following files into your own project root and modify them as needed:
dev/openmage/docker-compose-production.yml→docker-compose.ymldev/openmage/nginx-admin.conf→nginx-admin.confdev/openmage/nginx-frontend.conf→nginx-frontend.confdev/openmage/Caddyfile-sample→Caddyfilepub/admin/→static/admin/pub/default/{favicon.ico,robots.txt}→static/default/
Then perform the following steps:
echo "COMPOSE_FILE=docker-compose-production.yml" >> .envto make the production stack the default- Add
BASE_URLandADMIN_URLto your.envfile cp Caddyfile-sample Caddyfileand edit theCaddyfileto reflect your domain names and Magento store codes- If you did not hard-code your admin domain name in
Caddyfileedit.envand make sure it includesADMIN_HOST_NAME - Run
docker compose up -dto launch your new production-ready environment! - Load your existing database into the MySQL container volume and copy an existing
local.xmlfile into theapp/etc/sub-directory of your OpenMage root (e.g.pub/app/etc/local.xmlfor composer installations with defaultmagento-root-dir).- OR copy
dev/openmage/install.shinto your root directory and run it to create a fresh installation.
- OR copy
Environment variables supported by the docker-compose-production.yml file and install.sh which may be set in .env when installing a new production environment:
SRC_DIR=./pub- relative path to the OpenMage root - corresponds to the composermagento-root-dirSTATIC_DIR=./static- relative path to the directory which contains custom static files to be served from the root - must contain a sub-directory foradminand each store view.BASE_URL=https://frontend.example.com/(overridesHOST_NAMEandHOST_PORT)ADMIN_URL=https://backend.exmaple.com/(overridesADMIN_HOST_NAMEandADMIN_HOST_PORT)
Warning
Backups, intrusion protection and other security features are not provided and are left up to you! This is simply a web server configuration that adds an easy to configure and maintain SSL termination.
Adding more store views¶
- Create your new website and/or store codes in OpenMage.
- Create new root static asset directories in your static asset directory such as
static/store1,static/store2, etc… - Edit
Caddyfileto map your domain name to the appropriateruncodeandruntype. - Configure the URLs in the System > Configuration.
- Set up your DNS and relaunch
Caddy(docker compose restart caddy).
Mapping paths to different stores can be done using additional reverse_proxy declarations. See @customfrontend as an example.