This is a simple bash script that allows you to create a container for a Magento 1 or 2 project with the ability to create/import/maintain an existing project
- Setup a Magento 1/2 project within minutes
- Create an empty Magento 2.x project (Open Source or Commerce)
- Import an existing Magento 1.x project by importing a .sql file
- Import an existing Magento 2.x project by importing a .sql file
- If you already have a container for mysql called "mysql", the script will automatically use it, otherwise it will create a new one
- One single container for Magento 1
- One single container for Magento 2
- One single container for Mysql
- Docker installed
- Docker accessible via command line using the command
docker
Execute the following command in your terminal in order to execute the installer. You need to have "git" and "curl" installed within your terminal.
bash <(curl -s -X GET "https://raw.githubusercontent.com/fsspencer/bash-docker-magento/master/dockerize?v='$(date +"%s")'") setup
This will install dockerize in ~/.dockerize/bin and create a symlink on the /usr/local/bin directory, and it will download each needed container for docker.
That will pull the necessary Docker images.
composer require fsspencer/dockerize-magento
This will create a dockerize file to your project root directory. You just need to run it:
./dockerize install
or
bash dockerize install
That will pull the necessary Docker images.
dockerize <action> <arguments...>
Actions:
Command | Description |
---|---|
install | Install Magento and MySQLย |
update | Check for updates |
init | Initialize Magento project |
bash | Connect to your docker container |
php | Executes php cli within your project root |
composer | Executes composer within your project root |
grunt | Executes grunt-cli Utility within your project root |
gulp | Executes gulp Utility within your project root |
npm | Executes npm within your project root |
mysql | Executes Connect to the MySQL client server |
n98 | Executes n98-magerun within your project root |
magento | Executes Magento 2 command line tool (e.g: dockerize magento setup:upgrade) |
config:url | Set automatically the Store URL among other things |
db:create | Creates new database |
db:import | Imports a .sql file located in the project root |
db:dump | Generates a database file in the project root compressed using gzip |
start | Start the server and all of its components |
stop | Stop the server |
remove | Removes local dockerize configuration |
setup | Installs dockerize locally on your computer |
self-update | Updates dockerize locally on your computer |
NOTE: All of this commands will work only for your project root directory. That means that if you want to use, for example, gulp on a specify directory within project project (e.g.: skin/frontend/myvendor/mytheme/) it won't work. In that case, you will need to use the "dockerize bash" command and navigate to that directory and use the gulp command from that place.
- Download a Magento clean instance from https://magento.com/tech-resources/download
- Uncompress the Magento code and go into the project root directory
- Execute the following from your root directory
dockerize init
- Follow the steps of the script
- Select
create new database
without importing anything - Go to your browser and navigate to the URL you picked (http://dev.local/ by default)
- Download your project code within any directory you want
- Copy a single sql file with a database dump to your project root
- Execute the following from your root directory
dockerize init
- Follow the steps of the script
- Select
create new database
andimport database
when the script asks. This will create your local.xml file, set your store URL and the rest
- Create a new directory for your project
- Execute the following from your root directory
dockerize init
- Follow the steps of the script
- Enter
Y
when it asks forcreate database
- Enter
n
when it asks forimport database
- Enter
Y
when it asks forinstall magento
and pick the version you want to install. This will do the rest for you - Go to your browser and navigate to the URL you picked (http://dev.local/ by default)
- Download your project code within any directory you want
- Copy a single sql file with a database dump to your project root
- Get a copy from the original app/etc/config.php
- Execute the following from your root directory
dockerize init
- Follow the steps of the script
- Select
create new database
andimport database
when the script asks. This will create your env.php file, set your store URL and the rest
The dockerize start
command will create a new config file inside ~/.dockerize directory.
That file will save some configuration parameters after you initialized the project for the first time, in order to prevent to execute the whole process twice.
Whenever you execute dockerize start
it will stop any magento docker container and initialize a new one with the current project.
If you want to reset the project dockerize configuration, you need to execute dockerize remove
within your Magento root directory.
If you are using a Magento 1 project
$ docker exec --user www-data -ti magento bash
If you are using a Magento 2 project
$ docker exec --user www-data -ti magento2 bash
This will locate you on the /var/www/html
directory, which is your root dir with permissions for www-data:www-data.
You can perform the following commands
$ dockerize mysql -e "your sql query;"
Or just enter to mysql server
$ dockerize mysql
If you have a mysql-client installed locally on your computer, you can connect to it using Docker default IP address 0.0.0.0
$ mysql -h 0.0.0.0 -uroot -proot
The dockerize command has the ability to work with npm, grunt and gulp for direct usage on the project root directory. It is ideal for Magento 2 usage, since the Gruntfile.js
and the package.json
resides on the root.
But if you want to use those commands on a different directory, you need to connect to your container using the bash
command first.
Scenario:
- You have a custom theme that uses Gulp in Magento 1.
- Your theme and gulpfile.js resides on skin/frontend/myvendor/mycustomtheme
Follow the next steps:
$ dockerize bash
# once you are on the magento container
$ cd skin/frontend/myvendor/mycustomtheme
$ npm install # in order to download the dependencies
$ gulp # run gulp with any defined task on your gulpfile.js
-
ERROR 3167 (HY000) at line XX: The 'INFORMATION_SCHEMA.SESSION VARIABLES' feature is disabled; see documentation for 'show_compatibility_56
Solution: Enter to your mysql server
$ dockerize mysql
, and execute the following queryset @@global.show_compatibility_56=ON;
. Then try to perform your action again and the error should be gone.
- Francis S. Spencer - [email protected]
- codealist.net