I have two diaries, one of what I eat the other is this one :e.

Docker WordPress + Mysql

Here how to create a WordPress container connected to a mysql container to get WordPress running on Docker

To start we create a docker network called ‘sites’ for mysql and WordPress containers

docker network create sites

Create and configure Mysql container

in this example we will create a mysql container that uses ‘/Volumes/CLOSED/sites/mysql’ to store its data, one mysql database called ‘portugaline’, one mysql user called ‘portugaline’ with the password ‘123ass’. This container is connected to docker network ‘sites’

docker run --name mysql --network sites -v /Volumes/CLOSED/sites/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=naoseinaosei -p 3306:3306 -d mysql:latest

Now we need to create a table for WordPress and its user

we connect to mysql on the container using the command:

docker exec -it mysql mysql -u root -p

Create the table, in this example portugaline

Now we create the user ‘userportugaline’ with the password ‘123asd’ and give full privileges to table ‘portugaline’

Create database portugaline
CREATE USER ‘userportugaline'@'%' IDENTIFIED BY ‘123asd’;
GRANT ALL PRIVILEGES ON portugaline.* TO ‘userportugaline'@'%';

Create WordPress Container

Now we can create our docker container called ‘portugaline’, on the network ‘sites’, using the folder ‘/Volumes/CLOSED/sites/portugaline’ as root for the WordPress installation.

docker run --name portugaline --network sites -p 80:80 -v /Volumes/CLOSED/sites/portugaline:/var/www/html -d wordpress

Now you just have to delete the file at WordPress installation called ‘wp-config.php’ (if you have any old one) and after navigate on your browser to ‘localhost’ and you can now configure WordPress as in any web hosting service. Just note the url for mysql is not ‘localhost’ it is the nome of the mysql container, in this example ‘mysql’.

Leave a Reply

Your email address will not be published. Required fields are marked *