Build and Release

A continuous learner for experience and life.

Wordpress in Docker

enter image description here

Install docker container

On Windows/MacOS X, please go to Docker-toolbox: https://www.docker.com/toolbox Following the instruction to install docker-toolbox;

Open the docker quickstart terminal:

enter image description here

Install mysql database

1
$ docker pull mysql

Install wordpress application

1
$ docker pull wordpress

Compose the application with database, with a file named: docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
wordpress:
  image: wordpress
  links:
    - db:mysql
  ports:
    - 8080:80

  net: "bridge"
  dns:
    - 8.8.8.8
    - 4.4.4.4

db:
  image: mysql
  environment:
    MYSQL_ROOT_PASSWORD: example

Launch the composed service

1
$ docker-compose up

The service should be launched as following:

1
2
3
4
5
6
7
8
db_1        | 2015-10-06 05:13:50 1 [Note] Event Scheduler: Loaded 0 events
db_1        | 2015-10-06 05:13:50 1 [Note] mysqld: ready for connections.
db_1        | Version: '5.6.27'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
wordpress_1 | WordPress not found in /var/www/html - copying now
wordpress_1 | Complete! WordPress has been successfully copied to /var/www/html
wordpress_1 | AH00558: apache2: Could not reliably determine the server's fully
wordpress_1 | [Tue Oct 06 05:15:13.163996 2015] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.14 configured -- resuming normal operations
wordpress_1 | [Tue Oct 06 05:15:13.164050 2015] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

Or run as background processes:

1
$ docker-compose up -d

The output console should like:

1
2
Starting wordpress_db_1...
Starting wordpress_wordpress_1...

You can take a look the background containers:

1
2
3
4
5
$ docker-compose ps
        Name                       Command               State          Ports         
-------------------------------------------------------------------------------------
wordpress_db_1          /entrypoint.sh mysqld            Up      3306/tcp             
wordpress_wordpress_1   /entrypoint.sh apache2-for ...   Up      0.0.0.0:8888->80/tcp 

Or stop the composed containers:

1
2
3
$ docker-compose stop
Stopping wordpress_wordpress_1... done
Stopping wordpress_db_1... done

Access the service with 2 steps:

1
2
3
4
5
6
7
# Get your container IP address (from another console):
$ docker-machine ls # to get the launched container
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM
default            virtualbox   Running   tcp://192.168.99.100:2376

$ docker-machine ip default
192.168.99.100

Now you can open a browser then try to access:

1
http://192.168.99.100:8080

Done!

References:

  1. https://docs.docker.com/compose/

Written with StackEdit.

Comments