How to install WordPress with Docker on OS Sierra

With individual Docker commands

  1. Install Docker for Mac
  2. $ docker run –name mysql-latest -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest
  3. $ docker run –name wordpress -p 8000:80 –link mysql-latest:mysql -d wordpress:4.7.3-php7.1-apache
  4. Visit http://0.0.0.0:8000 and configure WordPress

With a Docker compose file

  1. Install Docker for Mac
  2. Save the following text to a ´~/dev /wordpress /website /docker-compose.yml´ file:
    version: '2'
    
    services:
      dbms:
        image: mysql:5.7
        volumes:
          - db_data:/var/lib/mysql
        ports:
          - 32768:3306
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: wordpress
          MYSQL_DATABASE: wordpress
          MYSQL_USER: wordpress
          MYSQL_PASSWORD: wordpress
    
      wordpress:
        depends_on:
          - dbms
        build: ./docker/wordpress
        image: wordpress:xdebug
        volumes:
          - .:/var/www/html
        ports:
          - 8000:80
        restart: always
        environment:
          WORDPRESS_DB_HOST: dbms:3306
          WORDPRESS_DB_PASSWORD: wordpress
          XDEBUG_CONFIG: remote_host=192.168.1.33
    
    volumes:
        db_data:
  3. Save the following text to a ´~/dev /wordpress /website /docker /wordpress /Dockerfile´ file
    FROM wordpress:4.7.3-php7.1-apache
    
    RUN yes | pecl install xdebug 
        && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini 
        && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini 
        && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
  4. Run everything: ´$ docker-compose up´
  5. Visit http://0.0.0.0:8000 and configure WordPress

Connect to the running dbms server from SequelPro

  1. Select the Standard tab
  2. Configure:
    Name: Docker for WordPress
    Host: 0.0.0.0
    Port: 32768
    Username: wordpress
    Password: wordpress
  3. Connect

Connect to a running server from a terminal

Example relative to connecting to the running dbms server.

  1. Find out the name of the server:
    $ docker-compose ps
           Name                      Command               State            Ports
    --------------------------------------------------------------------------------------
    website_dbms_1        docker-entrypoint.sh mysqld      Up      0.0.0.0:32768->3306/tcp
    website_wordpress_1   docker-entrypoint.sh apach ...   Up      0.0.0.0:8000->80/tcp
  2. Connect to the ´website_dbms_1´ server:
    $ docker exec -it website_dbms_1 bash
    root@7d36d19c7df4:/#
  3. Then, for example, find out the server IP:
    root@7d36d19c7df4:/# hostname -I
    172.18.0.2

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.