SlideShare a Scribd company logo
1 of 21
Download to read offline
><
DOCKERIZE
LARAVEL APPLICATION
Afrimadoni Dinata (afrimadoni@mbiz.co.id)
1DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
><
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
><
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
>< 4
Local Installation
DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
>< 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
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
><
02Required
Container
7
1. App
• Nginx
• PHP5-FPM
2. MySQL
><
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
><
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 .
><
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
>< 11DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
><
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
>< 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
><
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
><
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
><
Open http://laravel.app:8000 from web browser
16DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
><
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
><
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
><
docker inspect docker_db_1
19
…
…
container ip address
DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
><
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
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/

More Related Content

What's hot

Docker on Google App Engine
Docker on Google App EngineDocker on Google App Engine
Docker on Google App Engine
Docker, Inc.
 
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Continuous Delivery in Enterprise Environments using Docker, Ansible and JenkinsContinuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Marcel Birkner
 

What's hot (20)

The Golden Ticket: Docker and High Security Microservices by Aaron Grattafiori
The Golden Ticket: Docker and High Security Microservices by Aaron GrattafioriThe Golden Ticket: Docker and High Security Microservices by Aaron Grattafiori
The Golden Ticket: Docker and High Security Microservices by Aaron Grattafiori
 
DockerCon SF 2015: Enabling Microservices @Orbitz
DockerCon SF 2015: Enabling Microservices @OrbitzDockerCon SF 2015: Enabling Microservices @Orbitz
DockerCon SF 2015: Enabling Microservices @Orbitz
 
Docker Continuous Delivery Workshop
Docker Continuous Delivery WorkshopDocker Continuous Delivery Workshop
Docker Continuous Delivery Workshop
 
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
 
Introduction to dockerfile, SF Peninsula Software Development Meetup @Guidewire
Introduction to dockerfile, SF Peninsula Software Development Meetup @Guidewire Introduction to dockerfile, SF Peninsula Software Development Meetup @Guidewire
Introduction to dockerfile, SF Peninsula Software Development Meetup @Guidewire
 
Windows server containers
Windows server containersWindows server containers
Windows server containers
 
Docker on Google App Engine
Docker on Google App EngineDocker on Google App Engine
Docker on Google App Engine
 
Docker-Hanoi @DKT , Presentation about Docker Ecosystem
Docker-Hanoi @DKT , Presentation about Docker EcosystemDocker-Hanoi @DKT , Presentation about Docker Ecosystem
Docker-Hanoi @DKT , Presentation about Docker Ecosystem
 
Architecting .NET Applications for Docker and Container Based Deployments
Architecting .NET Applications for Docker and Container Based DeploymentsArchitecting .NET Applications for Docker and Container Based Deployments
Architecting .NET Applications for Docker and Container Based Deployments
 
DockerCon SF 2015: Docker Security
DockerCon SF 2015: Docker SecurityDockerCon SF 2015: Docker Security
DockerCon SF 2015: Docker Security
 
Docker 101 Checonf 2016
Docker 101 Checonf 2016Docker 101 Checonf 2016
Docker 101 Checonf 2016
 
Docker - 15 great Tutorials
Docker - 15 great TutorialsDocker - 15 great Tutorials
Docker - 15 great Tutorials
 
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Continuous Delivery in Enterprise Environments using Docker, Ansible and JenkinsContinuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
 
Continuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and JenkinsContinuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and Jenkins
 
Building Reusable Development Environments with Docker
Building Reusable Development Environments with DockerBuilding Reusable Development Environments with Docker
Building Reusable Development Environments with Docker
 
Docker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken CochraneDocker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken Cochrane
 
Dockerizing your applications - Docker workshop @Twitter
Dockerizing your applications - Docker workshop @TwitterDockerizing your applications - Docker workshop @Twitter
Dockerizing your applications - Docker workshop @Twitter
 
Continuous Integration using Docker & Jenkins
Continuous Integration using Docker & JenkinsContinuous Integration using Docker & Jenkins
Continuous Integration using Docker & Jenkins
 
Native Containers on Windows 10 & Windows Server 2016 using Docker
Native Containers on Windows 10 & Windows Server 2016 using DockerNative Containers on Windows 10 & Windows Server 2016 using Docker
Native Containers on Windows 10 & Windows Server 2016 using Docker
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 

Similar to Dockerize Laravel Application

Developing and Deploying PHP with Docker
Developing and Deploying PHP with DockerDeveloping and Deploying PHP with Docker
Developing and Deploying PHP with Docker
Patrick Mizer
 

Similar to Dockerize Laravel Application (20)

Docker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak PeekDocker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak Peek
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안
 
Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016
 
Docker fundamentals
Docker fundamentalsDocker fundamentals
Docker fundamentals
 
Docker: A New Way to Turbocharging Your Apps Development
Docker: A New Way to Turbocharging Your Apps DevelopmentDocker: A New Way to Turbocharging Your Apps Development
Docker: A New Way to Turbocharging Your Apps Development
 
Developing and Deploying PHP with Docker
Developing and Deploying PHP with DockerDeveloping and Deploying PHP with Docker
Developing and Deploying PHP with Docker
 
Docker 進階實務班
Docker 進階實務班Docker 進階實務班
Docker 進階實務班
 
廣宣學堂: 容器進階實務 - Docker進深研究班
廣宣學堂: 容器進階實務 - Docker進深研究班廣宣學堂: 容器進階實務 - Docker進深研究班
廣宣學堂: 容器進階實務 - Docker進深研究班
 
Improve your Java Environment with Docker
Improve your Java Environment with DockerImprove your Java Environment with Docker
Improve your Java Environment with Docker
 
Docker
DockerDocker
Docker
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
 
Containerizing Web Application with Docker
Containerizing Web Application with DockerContainerizing Web Application with Docker
Containerizing Web Application with Docker
 
Docker for developers on mac and windows
Docker for developers on mac and windowsDocker for developers on mac and windows
Docker for developers on mac and windows
 
Docker in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday development
 
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHPHands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
 
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
 
Docker module 1
Docker module 1Docker module 1
Docker module 1
 
From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016
 
GDG-ANDROID-ATHENS Meetup: Build in Docker with Jenkins
GDG-ANDROID-ATHENS Meetup: Build in Docker with Jenkins GDG-ANDROID-ATHENS Meetup: Build in Docker with Jenkins
GDG-ANDROID-ATHENS Meetup: Build in Docker with Jenkins
 
Тарас Кирилюк — Docker basics. How-to for Drupal developers
Тарас Кирилюк — Docker basics. How-to for Drupal developersТарас Кирилюк — Docker basics. How-to for Drupal developers
Тарас Кирилюк — Docker basics. How-to for Drupal developers
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

Dockerize Laravel Application

  • 1. >< DOCKERIZE LARAVEL APPLICATION Afrimadoni Dinata (afrimadoni@mbiz.co.id) 1DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
  • 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
  • 4. >< 4 Local Installation DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
  • 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
  • 16. >< Open http://laravel.app:8000 from web browser 16DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
  • 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
  • 19. >< docker inspect docker_db_1 19 … … container ip address DevOps with Container | 30 April 2016 | Microsoft Indonesia, Gedung BEJ Lt. 18, Jakarta
  • 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/