tuto-simplon-docker-nginx-php-slim-twig-mysql

image

Docker nginx boilerplate

A simple static website boilerplate based on docker and nginx

Installation

To run the app, you need to have composer, php-xml, docker, docker-compose and dnsmasq installed.

PHP

  1. Install composer sudo apt install composer
  2. Install php-xml sudo apt install php-xml
  3. To install dependencies, go to the default folder and run : composer install

Docker engine

  1. Remove docker older version sudo apt-get remove docker docker-engine docker.io
  2. As always, apt update before anything ... sudo apt-get update -y
  3. allow Docker to use the aufs storage drivers. sudo apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
  4. Install packages to allow apt to use a repository over HTTPS sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
  5. Add GPG key curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  6. Add repository sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  7. update apt list sudo apt-get update -y
  8. install docker latest version sudo apt-get install -y docker-ce

source : https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#uninstall-old-versions

Docker compose

  1. download docker compose in /usr/local/bin/docker-compose
  sudo curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  1. make docker-compose executable sudo chmod +x /usr/local/bin/docker-compose
  2. Installing command completion sudo curl -L https://raw.githubusercontent.com/docker/compose/1.17.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
  3. Optional, add current user to docker group sudo usermod -a -G docker $USER

source : https://docs.docker.com/compose/install/

dnsmasq

In order to redirect .dev tld to localhost, you need dnsmasq. To install it, do the following on ubuntu :

  1. edit /etc/NetworkManager/NetworkManager.conf and replace dns=dnsmasq by #dns=dnsmasq
  2. run sudo apt-get install dnsmasq
  3. edit /etc/dnsmasq.conf and add those lines to the file :
  listen-address=127.0.0.1
  bind-interfaces
  address=/dev/127.0.0.1
  1. run sudo netstat -plant | grep :53 and look for NUMBER/dnsmasq
  2. run sudo kill -9 NUMBER replace NUMBER by the number(s) you have seen in previous step.
  3. run sudo systemctl restart dnsmasq.service, this will restart the dnsmasq service.
  4. edit /etc/dhcp/dhclient.conf and uncomment (remove the #) on this line : prepend domain-name-servers 127.0.0.1;
  5. run sudo systemctl restart NetworkManager.service to restart the network manager, you will temporarily lost your network connection.

source : https://www.leaseweb.com/labs/2013/08/wildcard-dns-ubuntu-hosts-file-using-dnsmasq/

Usage

mysql

to run mySQL cli, just connect to the container : docker-compose exec mysql /bin/bash and run mysql -u root -p it will ask you the root password : root