WordPress on Docker Quickstart
Super quick guide to getting the official WordPress Docker image running with HTTPS without the need for an additional image for HTTPS proxy. The guide assumes that you know the basics of docker and just want to get an https version of WordPress going.
This guide assumes you’ve installed docker and docker-compose. Just as a point of order – I had permission issues on Arch when I first installed and started the docker service. It was a long time ago so I can’t recall the steps I took to rectify it. Your mileage may vary depending on your platform – but for the purposes of this guide, I hope you’re on Linux/OSX!
Also this guide is pretty much just an expanded version of this GitHub issue answer by AlexanderOMara
Create your project folder – for the rest of this guide, I’ll call mine “projectx”.
Inside the projectx/ folder create 2 files: Dockerfile and docker-compose.yml. Next, create a directory called wp-app.
Here is a base Docker file to get the official WordPress image to use https:
FROM wordpress:latest RUN apt-get update && apt-get install -y --no-install-recommends ssl-cert && rm -r /var/lib/apt/lists/* && a2enmod ssl && a2ensite default-ssl EXPOSE 80 443
Docker Compose File
And here is your docker-compose.yml file, swap out environment variables for your own. Also, take note of the example.test part, that’s the URL we’re going to view the WordPress installation on when the containers are up and running…
version: '3' services: projectxdb: image: mysql:latest volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: myRootPassword MYSQL_DATABASE: wpDatabaseName MYSQL_USER: wpUser MYSQL_PASSWORD: wpPassword projectxwp: build: context: ./ depends_on: - projectxdb volumes: - ./wp-app:/var/www/html extra_hosts: - "example.test:127.0.0.1" ports: - "80:80" - "443:443" restart: always environment: WORDPRESS_DB_HOST: projectxdb:3306 WORDPRESS_DB_USER: wpUser WORDPRESS_DB_NAME: wpDatabaseName WORDPRESS_DB_PASSWORD: wpPassword volumes: db_data:
You want to run the following command: docker-compse build. This will use the Dockerfile to create the image for the WordPress container, if what I just said sounds like obfuscated English, turn back now and go and read the Docker intro.
Next run docker-compose up and if the sun and stars have aligned in a mystical way, it will build all the required images and get the containers running. You can access all WordPress code in the wp-app folder.