How to install WordPress on Docker

No comments
Let's create container for WordPress that will host our site and protected by SSL.

We create one container for MySQL database and configure it via environment variables. Next we create WordPress container that links to mysql container and we can use mysql as hostname for our application. For WordPress we also set LETSENCRYPT_HOST for SSL and VIRTUAL_HOST for nginx-proxy.
docker-compose.yml:
mysql:
  restart: always
  image: mariadb:10.0
  hostname: mysql
  volumes:
    - /etc/localtime:/etc/localtime:ro
    - ./mysql:/var/lib/mysql
  environment:
    - MYSQL_ROOT_PASSWORD=rootpassword
    - MYSQL_DATABASE=site
    - MYSQL_USER=mysqluser
    - MYSQL_PASSWORD=mysqlpass

wordpress:
  restart: always
  image: wordpress
  hostname: example.com
  volumes:
    - /etc/localtime:/etc/localtime:ro
    - ./wordpress:/var/www/html
  links:
    - mysql:mysql
  environment:
    - "VIRTUAL_HOST=example.com,www.example.com"
    - "LETSENCRYPT_HOST=example.com,www.example.com"
    - "LETSENCRYPT_EMAIL=email@example.com"

Start stack with
docker-compose up -d

and don't worry about docker or server restart. restart: always will start container after different issues or unplanned reboots.

No comments :

Post a Comment