Install Wordpress with docker

Page content

Summary

docker run --restart=always -e MYSQL_ROOT_PASSWORD=aqwe123 -e MYSQL_USER=wpuser -e MYSQL_PASSWORD=wpuser@ -e MYSQL_DATABASE=wordpress_db -v /Users/cychong/Dropbox/Apps/wordpress/database:/var/lib/mysql --name mysql -d mysql

docker run --restart=always -e WORDPRESS_DB_USER=wpuser -e WORDPRESS_DB_PASSWORD=wpuser@ -e WORDPRESS_DB_NAME=wordpress_db -p 80:80 -v /Users/cychong/Documents/wordpress/html:/var/www/html -v /Users/cychong/Documents/wordpress/uploads:/var/www/html/wp-content/uploads -v /Users/cychong/Documents/wordpress/conf/php_uploads.ini:/usr/local/etc/php/conf.d/uploads.ini --link mysql:mysql --name wpcontainer -d wordpress

If required, import database to mysql (Once wordpress data is imported into mysql, upgrading mysql does not requires re-import ingof wordpress data)

mysql

install container

cychong:~ cychong$ docker run --restart=always -e MYSQL_ROOT_PASSWORD=aqwe123 -e MYSQL_USER=wpuser -e MYSQL_PASSWORD=wpuser@ -e MYSQL_DATABASE=wordpress_db -v /Users/cychong/Dropbox/Apps/wordpress/database:/var/lib/mysql --name mysql -d mysql
Unable to find image 'mysql:latest' locally
latest: Pulling from library/mysql
aa18ad1a0d33: Pull complete 
a5745c3b8bcc: Pull complete 
76375fcd129c: Pull complete 
4f72cfb004cf: Pull complete 
1d6a01e515fb: Pull complete 
a71e1163fa7e: Pull complete 
8c1a568fa442: Pull complete 
e7a69cecc173: Pull complete 
9759a0f979a1: Pull complete 
3f71dac6110f: Pull complete 
58f37de54392: Pull complete 
Digest: sha256:790b7b18b832822ef400e44ad9fac885a746db1a7028ec52325730cf9b831753
Status: Downloaded newer image for mysql:latest
b1f54c680120898fc7ff16751048fe18ae461399d5d7f10308c156c68d40577b

check container is started

cychong:~ cychong$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
b1f54c680120        mysql               "docker-entrypoint..."   13 seconds ago      Up 10 seconds       3306/tcp                 mysql
dea965b550e6        ghost:latest        "docker-entrypoint..."   8 days ago          Up 8 days           0.0.0.0:2368->2368/tcp   ghost

check files are located where volume is mounted

cychong:~/Dropbox/Apps/wordpress/database cychong$ ls
auto.cnf		ib_buffer_pool		mysql			server-key.pem
ca-key.pem		ib_logfile0		performance_schema	sys
ca.pem			ib_logfile1		private_key.pem		wordpress_db
client-cert.pem		ibdata1			public_key.pem
client-key.pem		ibtmp1			server-cert.pem

wordpress

install container

cychong:~ cychong$ docker run --restart=always -e WORDPRESS_DB_USER=wpuser -e WORDPRESS_DB_PASSWORD=wpuser@ -e WORDPRESS_DB_NAME=wordpress_db -p 80:80 -v /Users/cychong/Documents/wordpress/html:/var/www/html -v /Users/cychong/Documents/wordpress/uploads:/var/www/html/wp-content/uploads -v /Users/cychong/Documents/wordpress/conf/php_uploads.ini:/usr/local/etc/php/conf.d/uploads.ini --link mysql:mysql --name wpcontainer -d wordpress
525ba1e4fff2caccc020960908e4f538be9512c2541e62a94c5a36a341e7ff3c

cychong:~ cychong$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
525ba1e4fff2        wordpress           "docker-entrypoint..."   44 seconds ago      Up 42 seconds       0.0.0.0:80->80/tcp       wpcontainer
b1f54c680120        mysql               "docker-entrypoint..."   11 minutes ago      Up 11 minutes       3306/tcp                 mysql
dea965b550e6        ghost:latest        "docker-entrypoint..."   8 days ago          Up 8 days           0.0.0.0:2368->2368/tcp   ghost

check containers

cychong:~ cychong$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                    NAMES
8ea2303518ad        wordpress           "docker-entrypoint..."   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp       wpcontainer
b1f54c680120        mysql               "docker-entrypoint..."   3 minutes ago        Up 3 minutes        3306/tcp                 mysql
dea965b550e6        ghost:latest        "docker-entrypoint..."   8 days ago           Up 8 days           0.0.0.0:2368->2368/tcp   ghost

check files

cychong:~ cychong$ ls Documents/wordpress/html/
index.php		wp-admin		wp-config.php		wp-links-opml.php	wp-settings.php
license.txt		wp-blog-header.php	wp-content		wp-load.php		wp-signup.php
readme.html		wp-comments-post.php	wp-cron.php		wp-login.php		wp-trackback.php
wp-activate.php		wp-config-sample.php	wp-includes		wp-mail.php		xmlrpc.php

mysql dump data is not imported.

copy mysql dump file to mounted volume directory

cychong:~ cychong$ cp wordpress.dump.0910 ~/Dropbox/Apps/wordpress/database

Login to mysql container

cychong:~ cychong$ docker exec -ti b1f54c680120 bash
root@b1f54c680120:/# ls
bin  boot  dev	docker-entrypoint-initdb.d  entrypoint.sh  etc	home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@b1f54c680120:/# cd /var/lib/mysql
root@b1f54c680120:/var/lib/mysql# ls
auto.cnf    client-cert.pem  ib_logfile0  ibtmp1	      private_key.pem  server-key.pem	    wordpress_db
ca-key.pem  client-key.pem   ib_logfile1  mysql		      public_key.pem   sys
ca.pem	    ib_buffer_pool   ibdata1	  performance_schema  server-cert.pem  wordpress.dump.0910

Import mysql dump file to mysql db

root@b1f54c680120:/var/lib/mysql# mysql -h localhost -u root -p wordpress_db < wordpress.dump.0910 
Enter password: 
root@b1f54c680120:/var/lib/mysql# 

This should be from the DB schema. Still don’t know if data is imported properly

root@b1f54c680120:/var/lib/mysql# mysqlshow -u root -p wordpress_db
Enter password: 
Database: wordpress_db
+-----------------------+
|        Tables         |
+-----------------------+
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_termmeta           |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
+-----------------------+

Install jetpack

And enable markdown from Jetpack Setting > Writing

Done

#wordpress #docker