Before we start to develop a simple module / widget, we need to set up our development environment. For that, we will use docker. You can use docker on Linux, Mac, and Windows (WSL2), hoverer there are small differences in usage and performance between those platforms. Now go and install docker and let’s get started.

CD to project directory

cd C:\laragon\www\prestashop

Creating docker network

 docker network create prestashop-net

Create MySQL docker container

docker run -ti --name ps-mysql --network prestashop-net -e MYSQL_ROOT_PASSWORD=admin -p 3307:3306 -v -d mysql:5.7

Create PrestaShop APP docker container

For Linux/Mac terminal run:

docker run -ti --name my-prestashop --network prestashop-net -e PS_DEV_MODE=false -e PS_INSTALL_AUTO=0 -e DB_SERVER=ps-mysql -e PS_DOMAIN=localhost:8080 -p 8080:80 -v .:/var/www/html/ -d prestashop/prestashop:1.7

For Windows PowerShell terminal run:

docker run -ti --name my-prestashop --network prestashop-net -e PS_DEV_MODE=false -e PS_INSTALL_AUTO=0 -e DB_SERVER=ps-mysql -e PS_DOMAIN=localhost:8080 -p 8080:80 -d -v ${PWD}:/var/www/html/ prestashop/prestashop:1.7 

//or  ... -v c:/laragon/www/prestashop:/var/www/html/ -d prestashop/prestashop:1.7 

! Note that on Windows machine you might need to wait about 40 second or longer. Before, the http://localhost:8080 will be available. This is docker bridge networking issue, as it add another networking layer (you could use host networking layer instead of bridge for better performance: performance-issues-running-nginx-in-a-docker-container). However, according to docker docs, the host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server. This is why it might be a good reason to use docker directly from a Linux machine (which might solved the performance issue).

For Windows, WSL2 terminal run:

docker run -ti --name my-prestashop --network prestashop-net -e PS_DEV_MODE=false -e PS_INSTALL_AUTO=0 -e DB_SERVER=ps-mysql -e PS_DOMAIN=localhost:8080 -p 8080:80 -d -v ${PWD}:/var/www/html/ prestashop/prestashop:1.7

//or  ... -v /mnt/c/laragon/www/prestashop:/var/www/html/ -d prestashop/prestashop:1.7

PrestaShop database configuration

You might wonder why your default 127.0.0.1:3306 (or 127.0.0.1:3307) is can not reach the database.

On docker run, you already defined the connection to database by setting this parameter:

Also, remember that when running MySQL container, you also predefined environment variable for root password.

In the above, you have to set user as root and pass as admin.

Now to reach the database from PrestaShop app you also need to set the same value ps-mysql which is the name of the MySQL container linked to the same docker network.

Install PrestaShop:

Network test

To explain the above network example, we can connect to one of the containers using docker exec.

# run - docker exec -it <container_name> /bin/bash, example:
docker exec -it my-prestashop /bin/bash

Install ping inside docker container (not installed by default).

apt-get update
apt-get install ping

Test connection to MySQL container by its name:

PrestaShop plugin development: https://www.youtube.com/watch?v=gaV_G8jGVUE
https://devdocs.prestashop-project.org/1.7/modules/concepts/widgets
dockerhub: https://hub.docker.com/r/prestashop/prestashop/
github: https://github.com/PrestaShop/docker
https://stackoverflow.com/questions/56292108/connection-to-server-in-docker-container-on-localhost-very-slow
Improve Docker performance on Windows: https://www.createit.com/blog/slow-docker-on-windows-wsl2-fast-and-easy-fix-to-improve-performance/
Change connection type from bridge to host: https://stackoverflow.com/questions/49023800/performance-issues-running-nginx-in-a-docker-container
Get better performance on Windows when mounting volumes directly on to WSL2 file system: https://stackoverflow.com/questions/63552052/docker-volumes-on-wsl2-using-docker-desktop

0
Would love your thoughts, please comment.x
()
x