Proactivity

Dockerize your Wordpress setup

Source

This is a super short tutorial on how to get your wordpress setup running in a snap.

Things we need - a linux system in cloud(i chose ubuntu) with internet connectivity and ideally a domain name you have purchased

Step 1 : connect your cloud instance of linux to your domain. a super tutorial digitalocean, aws .Other setups are similar. check their help. Very soon - your domainname will start to point to an ugly page saying ‘page not found’. this is your success point (most likely)

Step 2 : ssh into your VPS/EC2 image

Step 3 : bang some commands

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
- mkdir ~/wordpress
- cd wordpress
- vi docker-compose.yml
paste this into the new docker-compose.yml file and hit save
(replace needed credentials as per your setup needs)
web:
image: wordpress
links:
- mysql
environment:
- WORDPRESS_DB_PASSWORD=(WORDPRESS_DB_PASSWORD)
- VIRTUAL_HOST=(YOUR_DOMAIN_NAME)
ports:
- "127.0.0.1:8081:80"
working_dir: /var/www/html
volumes:
- /wordpress/wp-content/:/var/www/html/wp-content
mysql:
image: mysql:5.7
ports:
- "127.0.0.1:3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=(WORDPRESS_DB_PASSWORD)
- MYSQL_DATABASE=(WORDPRESS_DB_NAME)
phpmyadmin:
image: corbinu/docker-phpmyadmin
links:
- mysql
ports:
- 8080:80
environment:
- MYSQL_USERNAME=root
- MYSQL_ROOT_PASSWORD=(MYSQL_ROOT_PASSWORD)
nginx:
image: jwilder/nginx-proxy
ports:
- 80:80
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro

Step 4 : Now you have all needed to get the setup start.

just make sure you have docker and docker-compose and docker is running in daemon mode

sudo apt-get install docker docker-compose

Step 5 : The magic commands are

docker-compose build && docker-compose up

once this finishes .. you’ll see lots of logs and you can hit back to see your domain show the wordpress installation page instead of the page not found page.

This shall be it. But you need to get rid of the console and let the setup run

So once you’ve confirmed all is fine. do a Ctrl + C to shut the images down. and then again start using

docker-compose build && docker-compose start

start runs the same stuff in daemonized mode.

Also - you shall understand that what docker did was fetching all the installation necessary material from official images for installing
mysql, nginx and wordpress and phpmyadmin and then installed all those as per your suggested variable data (db name , password etc.) magical, no ?

actually the catch is that you still need to follow where those directories are linked in order to make changes to those directories. example - you’ll need to change permissions for the wp-content in order to copy themes into it. so it’s a short-cut, but you still shall be helped by gaining clarity with directory structure as you move along. But all this saves you from the deadline sword. Doesn’t it ?