Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WordPress Development with Docker

WordPress Development with Docker

This deck presents a basic concept of Docker and utilizing it in WordPress development.

Avatar for Ian Tumulak

Ian Tumulak

July 06, 2019

Other Decks in Programming

Transcript

  1. Session Breakdown • Getting to know Docker • What is

    Docker • The concept and visualization of Containerization • Getting started • Prerequisites/Installation • Creating our WordPress install via command-line • Creating our WordPress install with Docker Compose
  2. What is Docker? Docker is an open-source platform designed to

    make it easier to create, deploy, and run applications by using containers.
  3. What is Docker? Docker is an open-source platform designed to

    make it easier to create, deploy, and run applications by using containers. With containerization, it allows us to package an application with all the parts it needs, such as libraries and other dependencies, and then ship it as one package.
  4. What is Docker? Docker is an open-source platform designed to

    make it easier to create, deploy, and run applications by using containers. With containerization, it allows us to package an application with all the parts it needs, such as libraries and other dependencies, and then ship it as one package. In essence, we can create our web service stack including WordPress in Docker!
  5. LAMP VAGRANT DOCKER Setup One time install on your local

    machine. WordPress and other dependencies are setup seperately. Provision a virtual machine and run script to setup from OS all the way down the required packages. May take a while to setup/provision. Creates your stack through containerization. The containers are link through a docker network. Setup is short after a docker image is downloaded. Resource Usage Vary Heavy. Needs to allocate CPU, RAM, and storage per VMs. Lightweight. Shares the kernel’s OS. No need to allocate resource as it shared amongs all containers. Workflow Due to the lack of isolation, database will be cluttered and shares server configuration accross all of your projects. Let’s you isolate but taking down a VMs and provision it again with new configuration will take a while. This is where debugging of other WordPress version is lagging. Jumping from latest to other version of WordPress is a breeze. You can easily switch a database or add service like elasticsearch.
  6. Simple visualization of LAMP with Docker... Latest C4 Going Live

    (Ship to Production). We don’t need PHPMyAdmin in the live site since it already serve its purpose as a development tool.
  7. “The beauty of Docker is that we can easily add

    or remove services without compromising our workflow. This makes testing a lot easier because we don’t have to do the “monkey work”, Docker does it for you. And the process of deploying project from staging to production is painstaking.”
  8. Prerequisites For Windows ✔ Virtualization Enabled in BIOS ✔ Windows

    10 64bit: Pro, Enterprise or Education (Build 15063 or later) ✔ CPU SLAT-capable feature ✔ 4GB RAM or higher
  9. Prerequisites For Windows ✔ Virtualization Enabled in BIOS ✔ Windows

    10 64bit: Pro, Enterprise or Education (Build 15063 or later) ✔ CPU SLAT-capable feature ✔ 4GB RAM or higher For Mac ✔ Mac hardware must be a 2010 or newer model ✔ Or macOS Sierra 10.12 and newer macOS releases are supported ✔ VirtualBox prior to version 4.3.30 must NOT be installed. Newer version is compatible ✔ 4GB RAM or higher
  10. Prerequisites For Windows ✔ Virtualization Enabled in BIOS ✔ Windows

    10 64bit: Pro, Enterprise or Education (Build 15063 or later) ✔ CPU SLAT-capable feature ✔ 4GB RAM or higher For Linux ✔ 64-bit installation ✔ Kernel version 3.10 or newer For Mac ✔ Mac hardware must be a 2010 or newer model ✔ Or macOS Sierra 10.12 and newer macOS releases are supported ✔ VirtualBox prior to version 4.3.30 must NOT be installed. Newer version is compatible ✔ 4GB RAM or higher
  11. Installing Docker For Windows ✔ Go to https://hub.docker.com/editions/community/docker-ce-desktop-windo ws ✔

    Double-click Docker for Windows Installer to run the installer. ✔ When the installation finishes, Docker starts automatically. A whale icon in the notification area indicates docker is running. For Mac ✔ Go to https://hub.docker.com/editions/community/docker-ce-desktop-mac ✔ Double-click Docker.dmg to start the install process. ✔ When the installation completes and Docker starts, the whale in the top status bar shows that Docker is running, and accessible from a terminal.
  12. Installing Docker For Linux ✔ Open terminal and run: sudo

    apt update && sudo apt install docker-ce
  13. Creating via command line mkdir -p your-project-folder/www && \ cd

    your-project-folder && \ docker network create your-wp-network && \ docker run --name your-wp-mysql-name –-network your-wp-network -e MYSQL_DATABASE=wordpress -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wordpress -d mysql:5.7 && \ docker run --name your-wp-name -it –-network your-wp-network -p 80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress
  14. Creating via command line mkdir -p your-project-folder/www && \ cd

    your-project-folder && \ docker network create your-wp-network && \ docker run --name your-wp-mysql-name –-network your-wp-network -e MYSQL_DATABASE=wordpress -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wordpress -d mysql:5.7 && \ docker run --name your-wp-name -it –-network your-wp-network -p 80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Creates project directory
  15. Creating via command line mkdir -p your-project-folder/www && \ cd

    your-project-folder && \ docker network create your-wp-network && \ docker run --name your-wp-mysql-name –-network your-wp-network -e MYSQL_DATABASE=wordpress -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wordpress -d mysql:5.7 && \ docker run --name your-wp-name -it –-network your-wp-network -p 80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Create a network to be in our container
  16. Creating via command line mkdir -p your-project-folder/www && \ cd

    your-project-folder && \ docker network create your-wp-network && \ docker run --name your-wp-mysql-name –-network your-wp-network -e MYSQL_DATABASE=wordpress -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wordpress -d mysql:5.7 && \ docker run --name your-wp-name -it –-network your-wp-network -p 80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Create mysql container
  17. Creating via command line mkdir -p your-project-folder/www && \ cd

    your-project-folder && \ docker network create your-wp-network && \ docker run --name your-wp-mysql-name –-network your-wp-network -e MYSQL_DATABASE=wordpress -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wordpress -d mysql:5.7 && \ docker run --name your-wp-name -it –-network your-wp-network -p 80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Create WordPress container
  18. Command Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress
  19. Command Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Our command to start and run the container
  20. Command Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Our options for this command
  21. Command Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Our image to containerized
  22. Option Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress We name our container. If we don’t name our container it will generate a random name.
  23. Option Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Interactive terminal
  24. Option Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Connect container to the network
  25. Option Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Publish container port to the Localhost.
  26. Option Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Bind mount a volume
  27. Option Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Set environment variables
  28. Option Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress Run container in detach mode. Do not show the process and only print the container ID.
  29. Option Breakdown docker run --name your-wp-name -it --network your-wp-network -p

    80:80 -v "$PWD/www":/var/www/html -e WORDPRESS_DB_HOST=your-wp-mysql-name:3306 -e WOR -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -d wordpress The image that we containerized.
  30. Commonly used commands: docker ps Display all active containers docker

    ps -a Display all both active and inactive containers docker exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command from a running container. Commonly use for running bash and running editors if I want to change in the wp-config.php docker pull [OPTIONS] name[:TAG|@DIGEST] Pull/Download an image docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Start and run a container docker stop [OPTIONS] CONTAINER [CONTAINER...] Stop one or more containers docker rm [OPTIONS] CONTAINER [CONTAINER...] Removes one or more container docker network COMMAND Manage networks docker COMMAND --help Display the description, usage, and options.
  31. Creating via command line mkdir -p your-project-folder/www && \ cd

    your-project-folder && \ curl -o docker-compose.yml https://gist.githubusercontent.com/itumulak/7 b6 -e WORd86 -e WOR5ce7 915ee8831c00f927 6 -e WOR9396 -e WOR4/raw/docker- compose.yml
  32. Commonly used commands: docker-compose up Create and start containers docker-compose

    up -d Create and start containers in detach mode docker-compose down Stop and remove containers, networks, images, and volumes docker-compose rm Removed stopped containers