Nowadays, docker community is increasing rapidly. The reason behind this is the advantages of docker containerisation over legacy servers and virtual machines. Today we will discuss how to initialise and run PrestaShop in a docker container.
There are a number of ways to initialise PrestaShop in docker container:
- Use Docker hub image
- Create own image from scratch
Use Docker hub PrestaShop image
The easiest way is to use the official PrestaShop image on Docker hub: https://hub.docker.com/r/prestashop/prestashop/
This image is initialised in 3 steps:
Step 1: Create a network:
now. Find out More
PrestaShop image needs a database container to manage database tables. Hence, we need a docker network to establish communication between PrestaShop and database container. Open terminal and run following command to create a docker network:
docker network create myprestashopnetwork
Of course, myprestashopnetwork is custom name for network so you can choose whatever name you want for your instance.
Step 2: Create a database container:
The database container is needed to manage PrestaShop database tables. This container is created using mysql image. Initialise this container with following command:
docker run -ti --name mypsmysql --network myprestashopnetwork -p 3307:3306 -d mysql:latest
Here, “mypsmysql” is name for database container and “myprestashopnetwork” is the network name.
Step 3: Initialise PrestaShop in docker container
At this point, we have our docker network and database container ready. Now initialise PrestaShop container with following command:
docker run -ti --name myprestashop --network myprestashopnetwork -p 8888:80 -d prestashop/prestashop:latest
- “myprestashop” is name for our PrestaShop container
- “myprestashopnetwork” is network name.
- Port number for container is 8888.
- “prestashop/prestashop:latest” is image name with latest tag. So this will install the latest available PrestaShop image in dockerhub. To this day, PrestaShop 18.104.22.168 is available as latest image.
After above steps are complete, go to http://localhost:8888/ and the PrestaShop installation page will load. From here, install the PrestaShop and use following values at the database connection step:
- Host: mypsmysql
- Login: root
- Password: admin
This is how we start PrestaShop in docker container. But as you can see, we need to install the PrestaShop after creating container at first time.
Automatic installation when running container
The docker hub image provides many environment options. Using these options, PrestaShop installs automatically when we initialise container with single command. After following Step-1 and Step-2 from above, run following command:
docker run -ti --name myprestashop --network myprestashopnetwork \ -e PS_INSTALL_AUTO=1 \ -e DB_SERVER=mypsmysql \ -e DB_USER=root \ -e DB_PASSWD=admin \ -e DB_NAME=myprestadb \ -e PS_INSTALL_DB=1 \ -e PS_FOLDER_INSTALL=install_renamed \ -e PS_FOLDER_ADMIN=admin_ps \ -p 8888:80 -d prestashop/prestashop:latest
As you can see, we have used many options to configure PrestaShop installation while initialising container:
- PS_INSTALL_AUTO: Automatic initialisation flag set to true.
- DB_SERVER, DB_USER, DB_PASSWD and DB_NAME: Database container details.
- PS_INSTALL_DB: Database installation flag set to true.
- PS_FOLDER_INSTALL: The name of install folder to rename after installation.
- PS_FOLDER_ADMIN: The name of admin folder after installation.
Please note that the installation takes sometime so the URL “http://localhost:8888/” will not work until the installation is complete. Meanwhile, you can check the logs by running following command:
docker logs myprestashop
The above command will show you the current logs of container like this:
* Checking if mypsmysql is available... * DB server mypsmysql is available, let's continue ! * Setting up install lock file... * Reapplying PrestaShop files for enabled volumes ... * No pre-install script found, let's continue... * Renaming install folder as install__ ... * Renaming admin folder as admin_ps ... * Create mysql database... * Creating database myprestadb... * <strong>Installing PrestaShop, this may take a while ...</strong> * Launching the installer script... -- Installation successful! -- * Removing install folder... * No post-install script found, let's continue... * Setup completed, removing lock file... * Almost ! Starting web server now * No init script found, let's continue... AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message [Mon May 16 05:58:36.375036 2022] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.52 (Debian) configured -- resuming normal operations [Mon May 16 05:58:36.375085 2022] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
After automatic installation process is complete, you can access the PrestaShop container on http://localhost:8888.
Alternatively, if you want to create own customised docker image with installed PrestaShop, read here : custom PrestaShop image from scratch.
That’s all about how to initialise PrestaShop in docker container. If any issue or doubt in the above process, please feel free to let us know in the comment section.
I would be happy to help.
For any doubt contact us at [email protected].