36
loading...
This website collects cookies to deliver better user experience
wordpress
image from DockerHub, which is a community where you can get a ton of pre-made images from. For the data image I picked the mysql
image.version: '3'
services:
db:
image: mysql:5.7
volumes:
- ./db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress123
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- '80:80'
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes: db_data:
db
and wordpress
. The important thing to note here is the way Docker Compose wires together the virtual network. It provides domains to the services with the names of the service, for example out MySQL Server will be available at mysql://db:3306
, while our WordPress would be reachable at http://wordpress
. Of course outside of the network (which is where we actually are) we can’t see that, so what we need to do is what you’d do with Docker: expose port 80
, which is taken by the Apache running within the container to some of our ports, in this example port 8000
. This means that we’ll be able to see our WordPress installation at http://localhost:8000
or in cases where Docker is running within a container (like on Windows), we need to use our $DOCKER_IP
variable or something similar.db
image has its working folder mapped to a local folder called db_data
. For this to work, we need to create this folder. If there is no such folder, nothing will happen, however it is handy to have all development data saved locally also.docker-compose.yml
is saved.docker-compose up -d
http://localhost:8000
, we should see the following screen:admin
(please do not do this in actual production builds), we should be greeted with the below screen upon logging in. Note that if you’ve mounted the volume db_data
to an actual folder, you should see MySQL server spitting out files related to our new WordPress installation. This is cool because you can just bundle this up at a later point and install it under an actual instance of MySQL Server or another Docker image and it will work fine with the same WordPress configurations.functions.php
for our own theme, to add custom post types later on.docker-compose.yml
:volumes:
- ./wordpress:/var/www/html
db
service config if you’re unsure which lines to put this on. We also need to restart our Docker Compose network for these changes to take effect. To do that, run:docker-compose down; docker-compose up -d
docker-compose restart
, but that will not reload configurations sadly.