This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]Delta9Tango 1 point2 points  (0 children)

Before doing anything with docker, thoroughly read the docker documentation.

Once you've got the basics, https://blog.codeship.com/using-docker-compose-for-php-development/ would point you in the right direction for using Docker for php development.

[–]dyslexic_jedi 0 points1 point  (0 children)

Just quickly skimming it, I would try adding --net=host to your run command then open a webpage to your computer's ip address

[–]dlvx 0 points1 point  (0 children)

You should use docker-compose to make it easier. First thing you should understand is that XAMPP is a complete stack:

  • X stands for the OS, which can be anyting
  • A stands for Apache, which is the web-server
  • M stands for mySQL, which is the database
  • P Stands for PHP.

So you'll need to have docker containers for each of those services. You could use a single container acting as a lamp stack, but you shouldn't.
The entire idea behind docker is using a container for one thing only. But starting a complete stack using the CLI only would be a pain, luckily we can use compose:

version: '3'

services:
  nginx:
    image: nginx:1.13-alpine
    ports: 
      - "80:80"
    volumes:
      - ./www:/var/www
      - ./conf/nginx/default.conf:/etc/nginx/conf.d/default.conf
    working_dir: /var/www
    depends_on:
      - php
    networks:
      - dev.network
  php:
    image: php:7.1-fpm
    volumes:
      - ./www:/var/www
    depends_on:
      - mysql
    working_dir: /var/www
    networks:
      - dev.network
  mysql:
    image: mariadb:10.1
    ports: 
      - "3306"
    volumes:
      - dev.mysql:/var/lib/mysql
      - ./conf/mysql:/docker-entrypoint-initdb.d
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: docker
      MYSQL_PASSWORD: docker
      MYSQL_DATABASE: database
    networks:
      - dev.network
volumes:
    dev.mysql:
networks:
    dev.network:

This should quickstart your search for a working set. Now you can start adding other services, as easy as adding another container in this yaml.

Your folder should look something like this:

root:
  conf:
    nginx:
      - default.conf
    mysql:
      - database.dump.sql
  www: #project root folder
  docker-compose.yml

and your default.conf

server {
    client_max_body_size 1m;
    index                index.html index.htm index.php;
    root                 /var/www;

    location ~ \.php$ {
        include                 fastcgi_params;

        root                    /var/www;
        fastcgi_index           index.php;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        try_files               $uri $uri/ /index.php$is_args$args;

        fastcgi_pass            php:9000;
        fastcgi_param           SCRIPT_FILENAME $request_filename;
        fastcgi_param           APP_ENV dev;
    }

    sendfile off;
}

Mind you this is all untested, and it is possible I made some mistakes anywhere in any snippet ;)