Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
[phpkenya meetup - 02:08:16] Docker & PHP Tutorial - Cheatsheet

Docker & PHP - Getting started Cheatsheet

Important Links

Adorable Idiot (My blog)

Docker official docs is a gold mine

PHP Kenya meetup group

Part 1 Docker, Getting Started & Installation - An Idoit Guide

Docker & PHP Blog Tutorial Part 1)

Installing Docker

ON UBUNTU 14-10

**Install from Repo **

sudo apt-get install -y docker.io  #
sudo usermod -aG docker vagrant

Test using this commands

docker info
docker version
sudo service docker restart

Windows & Mac users

I recommend using Docker ToolBox

Docker official docs is a gold mine

Part 2 Introduction to Docker & PHP (Talk at PHP User Group Kenya)

Session slides available here

Running your first container

 docker ps                         // show running containers
 docker ps -a                      // show running and exited containers
 docker run -it ubuntu             // Pull & run an ubuntu container in interactive mode
 lsb_release -a 
 docker inspect                    //check container properties
 docker stop
 docker rm <cont id>               //removes the specified container
 docker rm $(docker ps -aq)        //removes all containers [docker ps -aq] returns all the containers ids
 docker images                     // check your local images
 docker pull                       // pull images
 docker rmi <image id>             // removes the specified image
 docker push
 docker login                      // login in to the docker registry   
 docker kill $(docker ps -q) && docker rm $(docker ps -aq)  //cleanup
 docker search nginx
 docker pull nginx

Building our first Image using Dockerfile

 docker build -t phpugke/apache .
 docker build -f SDockerfile2 -t phpugke/apache .

Working with PHP (Docker & Laravel)

 docker build -t phpugke/laravel .
 docker run -p 80:80 -p 443:443 -d phpugke/laravel    //landing pages
 docker run -p 80:80 -p 443:443 -v /CodePath/app/:/var/www/laravel/app/ -v /CodePath/public/:/var/www/laravel/public/ -d phpugke/laravel //your app

I'll recommend you look at LaraDock and get to know Docker compose

Quick tools eg Loadtester with Siege

 docker build -t otienojulie/siege .
 docker run --rm -t otienojulie/siege -d1 -r10 -c25 -t36 example.com

###Live Production Environment Demo (My Ghost Blog ) with Digital Ocean Get $10 cloud credit here

** Create folder to keep ghost data & create the config.js **

 mkdir ghost
 cd ghost
 vim config.js // enter your nginx configs for ghost sample is in the Ghost folder

Tell docker where our ghost data is and how to find the container

 docker run -v $(pwd):/ghost-override --name=ghostdata ubuntu

Create the ghost container

 docker run -d --volumes-from ghostdata --name=ghost -p 80:2368 ghost
 docker ps -a   //confirm sanity

Go to Your-IP-ADDRESS using your browser

[UPDATE] I am looking the Nginx Dockerfile seem to have some issues, For now leave it the above command

###BUT, We a robust server that can handle multiple sites, so we setup Nginx###

Create folder to keep nginx data, logs & other config files

 mkdir -p ~/nginx/{logs,certs,sites-enabled}

Tell docker where our nginx data is and how to find the container

 cd nginx  // just to make sure pwd doesnt break in the below command
 docker run -v $(pwd)/logs:/var/log/nginx -v $(pwd)/certs:/etc/nginx/certs -v $(pwd)/sites-enabled:/etc/nginx/sites-enabled --name=nginxdata ubuntu

Add the blog-conf file to the sites-enabled folder & Edit the server_name and access_log name Stop the ghost container to free port 80

 docker stop ghost
 docker rm ghost
 cd sites-enabled
 vim blog_conf // enter your nginx configs for your blog sample is in the Ghost folder 

restart the ghost container without port arg cause we shall serve it using nginx

 docker run -d --volumes-from ghostdata --name=ghost ghost

Create the Nginx container

 docker run -d -p 80:80 -p 443:443 --link ghost:ghost --volumes-from=nginxdata --name=nginx nginx

Confirm Sanity

 docker restart ghost nginx
 docker ps

Your blog is production ready!!!

Part 3 Docker Compose & Container Orchestration for Idiots

Part 4 Building a Continuous Integration & Deployment for Idiots

Part 5 Building a Horizontal Scalable Web API with HAProxy and Digital Ocean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment