A dockerized magento 2 community environment ready for development or production.
APACHE-2.0 License
A dockerized magento 2 community environment ready for development or production. It supports magento 1.9.x for development
Inspired from dockerize-magento2
All containers run on Alpine Linux. As a result, the images are smaller, faster and all the containers work with the same rules.
Magento is totally independant from Painless Magento 2
. Magento lives inside the src
directory. This is a volume in the php
container, so you can use Painless Magento 2
to develop stores, websites or Magento extensions. After, you can use the same system for production or take your code from the source directory to use as you need.
Composer runs out the containers. Composer is left outside on purpose to keep the containers small and facilitate their use. You always have access to the code in the volume src
. You should use Composer in the host machine. You can apply your changes without stoping the containers. To run compose commands, go to src
directory.
ex: install Fooman Goolge Analytics.
cd src
composer require fooman/googleanalyticsplus-m2
cd ..
sh bin/console.sh mage setup:upgrade
It includes, alpine latest, php 7,2 , nginx run by socket, mariadb, redis, opcache and let's encrypt; xdebug is only install when the enviroment is set in .env
file as developer.
For Linux users you must have a recent version of docker and docker-compose installed.
If you are a Mac or Windows user, use Docker Desktop or Docker Toolbox.
You need to have php
and composer
installed on your host machine.
You need to have all php extensions
required by magento installed on your host machine :
ext-bcmath
ext-ctype
ext-curl
ext-dom
ext-gd
ext-hash
ext-iconv
ext-intl
ext-mbstring
ext-openssl
ext-pdo_mysql
ext-simplexml
ext-soap
ext-spl
ext-xsl
ext-zip
lib-libxml
The instalation process is the same for development, staging or production. The difference is in the information you use to fill the .env
file.
To start, use .env.sample
to create this file.
cp .evn.sample .env
Open the file and fill each variable. Each variable has values by default, you can use them as it for development but please for your own safety change all for your installation in production.
take a backup from your data base.
Add your existing Magento 2 code inside the src
directory.
Magento 2 only: In the root directory of this project run the installer.
sh bin/console.sh install
Connect with the phpadmin you just install and use your data base backup for apply your last version. Just use the port you set on .env
file.
config/backups
it will appears inside container at the address /backups
docker-compose exec mysql sh -c="mysql -u $DATABASE_USER -p $DATABASE_NAME < /backups/$BACKUP_FILE_NAME"
Done, you can start to use or develop your old magento project.
In the root directory of this projet, run this line:
rm src/.gitkeep && composer create-project --repository=https://repo.magento.com/ magento/project-community-edition src && touch src/.gitkeep
The first time it will ask for your magento authentication keys, click here for obtain yours if you don't have ones.
In the root directory of this project run the installer.
sh bin/console.sh install
Done, you can start to use or develop magento 2
Painless Magento 2
comes with bin/console.sh
script that can be used to install Magento, execute Magento's commands, create config files and manage docker containers:
Trigger the Magento 2 installation process:
sh bin/console.sh install
Start the docker containers:
sh bin/console.sh start
Stop the docker containers:
sh bin/console.sh stop
Execute bin/magento
inside the docker container:
sh bin/console.sh mage [arguments]
For more information on how to use docker-compose
visit: https://docs.docker.com/compose/
You can customize them in the .env
file before run the instalation
Variable | Default Value | Notes |
---|---|---|
MAGE_DOMAIN | painlessmagento.test | |
ROOT_PROJECT | Commented | DOCKER-TOOLS USERS ONLY patch for use volumes, outsite c:/Users in windows, 1) add the project's directory to the shared directories in your VM. 2) uncomment ROOT_PROJECT line and write the address you add inside the VM. |
U_ID | 33 | Use the uid of the host owner of /src directory Using bash or bash for windows you can get this using echo $UID
|
WEB_USER | www-data | Using bash or bash for windows you can get this using echo $USERNAME
|
NETWORK_BASE | 169.254.81 | first 3 parts of local ip network you like to use |
PHPMYADMIN_PORT | 8080 | You can access phpmyadmin using http://MAGE_DOMAIN:PHPMYADMIN_PORT TODO: add phpadmin to nginx adding a subdomain and add SSL certification
|
MAGENTO VARIABLES | ||
ENVIROMENT | developer | Magento accepts this three enviroments: - default - developer - production |
DATABASE_NAME | painlessmagento | |
DATABASE_USER | magento | |
DATABASE_PASSWORD | magneto123 | |
DATABASE_ROOT_PASSWORD | magento123_root | |
ORDER_PREFIX | inv | |
BACKEND_FRONTNAME | management | |
ADMIN_USERNAME | admin | |
ADMIN_FIRSTNAME | Jhon | |
ADMIN_LASTNAME | Doe | |
ADMIN_EMAIL | [email protected] | |
ADMIN_PASSWORD | Magento123 | |
DEFAULT_LANGUAGE | en_US | |
DEFAULT_CURRENCY | USD | |
DEFAULT_TIMEZONE | America/New_York | |
EMAIL_SENDER | [email protected] | |
SMTP_SERVER | smtp.mailtrap.io | I like use mailtrap for development |
SMTP_PORT | 587 | |
SMTP_USER | Your_User | |
SMTP_PASS | Your_Password |
Use at your own risk, no waranties included.
You can use the default enviroment values for development, it's not big deal but.
I strongly recomemnd change ALL the values in the .env when you use PainlessMagento for production.
Painless Magento 2 is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.
starting point and base of this project:
https://github.com/arvatoSCM/dockerize-magento2
use docker in windows home:
docker-compose file reference:
https://docs.docker.com/compose/compose-file/
Handling permissions with docker volumes:
https://denibertovic.com/posts/handling-permissions-with-docker-volumes/
docker nginx, let's encrypt configuration:
Add users in alpine linux:
Redis configuration:
https://devdocs.magento.com/guides/v2.3/config-guide/redis/redis-session.html
https://devdocs.magento.com/guides/v2.3/config-guide/redis/redis-pg-cache.html
magento cli instalation guide:
set cronjob in bash file: