Deploy existing Prestashop to server using Docker

Viewed 4981

I've created PrestaShop store on server. Is there any possible way to use docker for my store and migrate it into another server using docker? I know that I'll need docker-compose but to be honest I don't know what to do with files on current server.

4 Answers

Ok, so I deeped into problem and solution for ma quesstion is as below. What I did is pull original image from prestashop and copy there my files.

Next step was use mariadb image. I had backup.sql file exported from previous store phpmyadmin

version: '2'

services: 
  prestashop:
    image: prestashop
    ports:
      - 80:80
    links:
      - mariadb:mariadb
    depends_on:
      - mariadb
    volumes:
      - ./src:/var/www/html
      - ./src/modules:/var/www/html/modules
      - ./src/themes:/var/www/html/themes
      - ./src/override:/var/www/html/override
    environment:
      - PS_DEV_MODE=1
      - DB_SERVER=mariadb
      - DB_USER=root
      - DB_PASSWD=root
      - DB_NAME=prestashop
      - PS_INSTALL_AUTO=0

  mariadb:
    image: mariadb
    volumes:
     - backup.sql:/docker-entrypoint-initdb.d
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=prestashop

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    links:
      - mariadb
    ports: 
      - 81:80 
    environment:
      - PMA_HOST=mariadb
      - PMA_USER=root
      - PMA_PASSWORD=root

The biggest issue is IP in docker-machine. Keep in mind that if you are using docker toolbox you have IP 192.168.99.100 but in Docker for Windows your IP depends on localhost (or just type localhost).

You can use this docker-compose.yml :

version: "3"
services:
  prestashop:
    image: prestashop/prestashop
    networks:
      mycustomnetwork:
    ports:
      - 82:80
    links:
      - mariadb:mariadb
    depends_on:
      - mariadb
    volumes:
      - ./src:/var/www/html
      - ./src/modules:/var/www/html/modules
      - ./src/themes:/var/www/html/themes
      - ./src/override:/var/www/html/override
    environment:
      - PS_DEV_MODE=1
      - DB_SERVER=mariadb
      - DB_USER=root
      - DB_PASSWD=mycustompassword
      - DB_NAME=prestashop
      - PS_INSTALL_AUTO=0

  mariadb:
    image: mariadb
    networks:
      mycustomnetwork:
    volumes:
      - presta_db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=mycustompassword
      - MYSQL_DATABASE=prestashop

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    networks:
      mycustomnetwork:
    links:
      - mariadb:mariadb
    ports:
      - 1235:80
    depends_on:
      - mariadb
    environment:
      - PMA_HOST=mariadb
      - PMA_USER=root
      - PMA_PASSWORD=mycustompassword

volumes:
  presta_db:

networks:
  mycustomnetwork:
    external: true

Replace mycustomnetwork and mycustompassword

Then run docker-compose up

Web url : localhost:82

PHP MyAdmin url : localhost:1235

You can follow this tutorial to setup Prestashop in a Docker environment.

https://hub.docker.com/r/prestashop/prestashop/

You will need to add your current files to the Prestashop container and most likely import your database in a MySQL container. Docker-compose will be used to launch those containers together. Once this is done, you will be able to deploy the whole thing anywhere.

You should also include bridge network in your compose file, some examples might work from here https://runnable.com/docker/docker-compose-networking.

This way db can be configured to be accessed only by prestashop on local docker network without being exposed outside. Presta db can also be pointed to the name of the running image, in case your IP changes or something. All what you would leave running is port 80 on the app.

Related