2. ><
Dockerizing an application is the process of converting an application to run within
a Docker container.
What is dockerize ?
2DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
3. ><
01Environment
Installation Overview
Local Installation
3
Install every single application, tools and library directly into
your development PC
Use Laravel Homestead
Install every single application, tools and library into a
virtual machine (with vagrant)
Use Docker
Install every single application, tools and library into
docker containers
5. >< 5
Use Laravel Homestead
DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
1. Install with command: vagrant box add laravel/homestead
2. Edit configuration file ~/.homestead/Homestead.yaml
3. Add the “domain” to he hosts file (/etc/hosts)
4. Launch vagrant box with command: vagrant up
6. >< 6
Use Docker
DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
1. Install docker engine
2. Create custom images
3. Use docker compose to run multiple container
4. Each container run in an isolated environment
8. ><
03Docker Machine
8
Docker Machine is a tool that lets you install Docker Engine
on virtual hosts, and manage the hosts with docker-
machine commands.
View all available machines:
docker-machine ls
Create new machine:
docker-machine create --driver virtualbox dev
Start a machine:
docker-machine start dev
9. ><
04Build Custom
Images
9
Nginx + PHP5-FPM
Build with Dockerfile
Use nginx:latest as base image
Build image with following command:
docker build -t doenikoe/laravel5:v1 .
10. ><
Dockerfile
10
FROM nginx
MAINTAINER Afrimadoni Dinata <doenikoe@yahoo.com>
RUN export DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get -y install php5 php5-cli php5-fpm sed git curl
RUN sed -i 's/cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php5/fpm/php.ini
RUN sed -i 's/user = www-data/user = nginx/g' /etc/php5/fpm/pool.d/www.conf
RUN sed -i 's/group = www-data/group = www-data/g' /etc/php5/fpm/pool.d/www.conf
RUN sed -i 's/listen.owner = www-data/listen.owner = nginx/g' /etc/php5/fpm/pool.d/www.conf
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
COPY default.conf /etc/nginx/conf.d/default.conf
COPY info.php /usr/share/nginx/html/info.php
COPY init.sh /usr/init.sh
VOLUME ["/usr/share/nginx/html"]
EXPOSE 80 443
CMD ["sh", "/usr/init.sh"]
DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
11. >< 11DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
12. ><
05Docker Compose
12
Docker Compose is a tool for defining and running
multi-container Docker applications. With Compose,
you use a Compose file to configure your application’s
services. Then, using a single command, you create
and start all the services from your configuration
Run docker compose with following command:
docker-compose up
13. >< 13DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
version: '2'
services:
web:
image: doenikoe/laravel5:v1
ports:
- "8000:80"
depends_on:
- db
volumes:
- ./web:/usr/share/nginx/html
db:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: laravel
command: "true"
docker-compose.yml
14. ><
06Install Laravel
14
Install laravel into local PC with composer:
composer create-project --prefer-dist laravel/laravel .
Set permission of storage folder (optional):
sudo chmod -R 777 storage
15. ><
07Configure Host
15
Add the following line to your hosts file:
192.168.99.100 laravel.app
Location of hosts file:
• mac: /etc/hosts
• linux: /etc/hosts
• windows: C:WindowsSystem32driversetchosts
17. ><
09Modify Container
17
Docker allow us to modify existing container and then save
the changes. Every changes that applied to single
container is possibly committed to a new image using the
“docker commit” command.
Get into container’s terminal:
docker exec -it docker_web_1 /bin/bash
Install php5-mysql extension:
apt-get install php5-mysql
Restart php5-fpm:
service php5-fpm restart
18. ><
10Database
Connection
18
Get the db container ip address:
docker inspect docker_db_1
Set laravel database configuration as follow:
DB_CONNECTION=mysql
DB_HOST=172.20.0.2
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=secret
Run the laravel migration script:
php artisan migrate
20. ><
11Docker Commit &
Docker Push
20
Commit container to new image:
docker commit -m “Added php5-mysql ext“ -a “John
Doe” docker_web_1 doenikoe/laravel5:v2
Login into docker (using docker hub account):
docker login
Push new image into docker hub:
docker push doenikoe/laravel5:v2
21. >< 21
Thank You
DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
https://github.com/doenikoe/devops-phpid
https://hub.docker.com/r/doenikoe/laravel5/