The goal is to have a local environment with:
- A web server (Apache) with PHP version 7.2 or above
- A MySQL (MariaDB) database server
- Magento Open Source Code
- Magento Open Source Sample Data
Clone this repo to your working directory.
Create a folder called instances within that directory.
Example:
/magento/magento2-dk/instances
Copy magento2-dk/debian_config/composer/auth.json.sample
to magento2-dk/debian_config/composer/auth.json
and enter your public (username) and private (password) access keys.
Example:
{
"http-basic": {
"repo.magento.com": {
"username": "<public_key>",
"password": "<private_key>"
}
}
}
Add an entry to your local hosts file to resolve the local magento2.loc domain:
Unix
sudo vi /etc/hosts
127.0.0.1 magento2.loc
Windows
Windows host file location is C:\Windows\System32\drivers\etc\hosts
Open file as administrator (or use visual studio code editor), add the following line:
127.0.0.1 magento2.loc
then save the file
Note: If you are using Windows without WSL, you must update magento2-dk/docker-compose_windows.yml
to match your installation directory like the following:
volumes:
- C:\PATH\TO\YOUR\magento\magento2-dk\instances:/var/www/html/shared
Open a terminal in that folder and run the following command:
For Unix/Mac/Windows with WSL
docker-compose up -d
Or, for Windows without WSL
docker-compose -f docker-compose_windows.yml up -d
This step will take a while.
After the docker images are successfully built, run the following command to access the container:
Unix/Mac
docker exec -ti m23 /bin/bash
Windows
winpty docker exec -it m23 //bin/sh
Getting Access to the Magento instance Once inside the container, run the following command to move the Magento directory to a shared folder and exit:
mv /var/www/html/magento2ce /var/www/html/shared/ && exit
You can now access the site:
- Frontend: http://magento2.loc:8080/
- Admin: http://magento2.loc:8080/admin (username: admin, password: mageU123)
If you are on Mac/Unix or Windows with WSL, you can use Mutagen. Click here for installation instructions.
Execute the following script in the root of your project for instructions on the most common commands.
You can also view the Mutagen documentation.
Unix/Mac
sh mutagen_session.sh
Windows with WSL
bash mutagen_session.sh
The commands are also listed below.
To create a mutagen session you need to use the create
command with the path to your working directory on your local machine.
Unix/Mac
sh mutagen_session.sh create /Users/<YOUR_USER>/<PATH>/<TO>/<YOUR>/magento/magento2-dk/instances/
Windows with WSL
bash mutagen_session.sh create C:\PATH\TO\YOUR\magento\magento2-dev-dk\instances\
After mutagen is started and all files are synchronized, the Magento code will appear in instances
folder of your working directory.
Mac/Unix
sh mutagen_session.sh pause
Windows with WSL
bash mutagen_session.sh pause
Mac/Unix
sh mutagen_session.sh resume
Windows with WSL
bash mutagen_session.sh resume
Mac/Unix
sh mutagen_session.sh terminate
Windows with WSL
bash mutagen_session.sh terminate
Mac/Unix
sh mutagen_session.sh list
Windows with WSL
bash mutagen_session.sh list
After the docker images are successfully built and running you can setup a new connection to the DB. Below we will describe steps for MySql Workbench SQL client (You are able to use any SQL client you wish).
MySql Workbench
Open MySql Workbench client and click to "MySql Connections +" button and you will see the "Setup New Connetcion" window
- Fill "Connection Name" field with any name you want - Example: dockerDB
- "Connection Method" is "Standard (TCP/IP)"
- Hostname is 127.0.0.1
- Port is 4306
- username is magento
- password is magento
- Default Schema is m2
- Click Ok to save your new connection
After the docker images are successfully built and running you can run the following command to go inside of the container:
Mac/Unix
docker exec -ti <CONTAINER_ID> /bin/bash
Windows
winpty docker exec -it <CONTAINER_ID> //bin/sh
Example:
Unix:
docker exec -ti m23 /bin/bash
Windows:
winpty docker exec -it m23 //bin/sh
To stop the VM, use the following command:
docker-compose stop
To start the VM, use the following command (note that you will need to start it if you reboot your computer):
docker-compose start
To run the Magento CLI command in a running container:
Mac/Unix
sh m23_config/bin/console execute ANY_MAGENTO_CLI_COMMAND
Windows
bash m23_config/bin/console execute ANY_MAGENTO_CLI_COMMAND
That's it, you have your VM for learning purposes for Magento 2.2 and Magento 2.3.
Open a terminal in your working directory and run the following command:
docker-compose down
Run the following command you should see something like table below:
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
mike/m23_config latest 167961367de5 12 days ago 3.39GB
mike/magento_config latest d26f7cd51da1 12 days ago 1.74GB
mike/debian_config latest bd3e96686fa0 12 days ago 923MB
debian latest 67e34c1c9477 3 weeks ago 114MB
Now you need copy IMAGE ID and use following command:
docker rmi -f IMAGE ID
Example
docker rmi -f 167961367de5
for every single image from the table