Use Docker for deploying WP

TurnToJPG -->

Just for swiftly deploy WP and test the RESTful API, I did following operations and runs a WP temporately.


Pull following containers:

$ docker pull mysql
$ docker pull wordpress
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              480ac552cd39        About an hour ago   192.8 MB
mysql               latest              98840bbb442c        39 hours ago        235.5 MB
wordpress           latest              9f51af77fd96        8 days ago          470.5 MB


Explanation for following commands, --name is the name for our container, -p 8038:80 is mapping the host machine’s 8038 port to container wordpress_1:

$ docker run --name mysql_1 -e MYSQL_ROOT_PASSWORD=xxxx -d mysql
$ docker run --name wordpress_1 --link mysql_1:mysql -p 8038:80 -d wordpress

Now open your browser to http://localhost:8038 and you got the wordpress installation window.


After we installed WP, we could install JSON REST API from:
After installation, we could test the REST API via curl:


View Docker status

First we should grab the docker’s PID via following command:

$ docker  inspect  --format "{{ .State.Pid }}"  mysql_1 
$ docker  inspect  --format "{{ .State.Pid }}"  wordpress_1

Then we could nsenter the docker container and view its status:

$ sudo nsenter --target 28254 --mount --uts --ipc --net --pid -- /bin/bash
$ sudo nsenter --target 28754 --mount --uts --ipc --net --pid -- /bin/bash

In the ‘attached’ environment we could inspect the status for corresponding services.

Stop docker contains

via docker stop we could simply stop the docker container:

[Trusty@~/code/30days/Docker]$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                  NAMES
0995854e2144        wordpress:latest    "/ apac   About an hour ago   Up About an hour>80/tcp   wordpress_1         
99d257ad6e24        mysql:latest        "/ mysq   About an hour ago   Up About an hour    3306/tcp               mysql_1             
[Trusty@~/code/30days/Docker]$ docker stop 0995854e2144
[Trusty@~/code/30days/Docker]$ docker stop 99d257ad6e24
[Trusty@~/code/30days/Docker]$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES