SlideShare une entreprise Scribd logo
1  sur  38
Télécharger pour lire hors ligne
learning:
with Thomas @ Search Investment Group
Slides & codes: http://bit.ly/thomasdocker
Ref: 8 surprising facts about real docker adoption
Ref: Docker Customers, StackShare
Virtual Machines Docker
Benefits
● Lightweight
● Experiment and use whatever technology fits best
● Having multiple versions of tools without crashing
(Java, Python 2 & 3, etc)
● Automated deployment
● Quickly and accurately set up environments for DEV, UAT, etc.
● Scale easily
Today’s Demo
● Install Docker
● Download and run a Hello World Docker image
● Compose our own Hello World Docker Image
● Compose our own Docker Image that contains a PHP-MySQL
application
Install Docker (MacOS)
https://www.docker.com/products/
Install Docker (Windows)
Hello World
Hello-world container
Docker Store
Find the Image
Hello World
$ docker --version
Docker version 1.13.0, build 49bf474
$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
$ docker run hello-world
Hello from Docker!
(...)
Ref for our “SSL Deep Inspection”:
Docker behind proxy that changes
ssl certificate
Basic Docker Commands
$ docker images
(list the images you pulled)
$ docker ps
(list the running containers)
$ docker ps -a
(list all containers, including exited)
$ docker [command] --help
(check the documentation)
$ docker rmi [image ID]
(remove the image by the associated ID
- you don’t have to type in full ID!)
$ docker stop [container ID]
(stop the running container by the ID)
$ docker rm [container ID]
(stop and remove the container from the
ps -a list)
$ docker ps -aq | xargs docker rm
(stop and remove all containers)
Build our own Hello World
Python container
Our hello-world container
Hello World in Python
$ echo 'print("Hello from Thomas")' > app.py
$ cat app.py
print("Hello from Thomas")
$ python app.py
Hello from Thomas
Docker Store
Dockerfile & docker-compose.yml
$ vi Dockerfile
FROM python
MAINTAINER Thomas Tong <hello@thomastong.me>
COPY app.py app.py
CMD python app.py
$ vi docker-compose.yml
helloworld:
build: .
Describes the necessary
steps to build the container
Describes the container in
its running state
(environment variables,
dependencies to others
containers, etc)
Ref: Docker Compose vs. Dockerfile
Compose a Docker Image
$ ls
Dockerfile app.py
docker-compose.yml
$ docker-compose build
Building helloworld
Step 1/4 : FROM python
latest: Pulling from library/python
5040bd298390: Pull complete
fce5728aad85: Pull complete
76610ec20bf5: Pull complete
52f3db4b5710: Pull complete
45b2a7e03e44: Pull complete
75ef15b2048b: Pull complete
e41da2f0bac3: Pull complete
Digest:
sha256:cba517218b4342514e000557e6e9100018f980cda866420
ff61bfa9628ced1dc
Status: Downloaded newer image for python:latest
---> 775dae9b960e
Step 2/4 : MAINTAINER Thomas Tong
<hello@thomastong.me>
---> Running in b257c26e3b5e
---> b6a9ca588053
Removing intermediate container b257c26e3b5e
Step 3/4 : COPY app.py app.py
---> c30eb29c8920
Removing intermediate container 5c74e320839d
Step 4/4 : CMD python app.py
---> Running in 5c2295d819ad
---> b54de6654b62
Removing intermediate container 5c2295d819ad
Successfully built b54de6654b62
Run the Docker Image
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
2helloworld_helloworld latest b54de6654b62 7 minutes ago 687 MB
python latest 775dae9b960e 7 minutes ago 687 MB
$ docker run [image name/ID]
Hello from Thomas
$ docker-compose up
Creating 2helloworld_helloworld_1
Attaching to 2helloworld_helloworld_1
helloworld_1 | Hello from Thomas
2helloworld_helloworld_1 exited with code 0
You can only use this after
building the image
Build and start according
to the Dockerfile and
docker-compose.yml, good
for development
Apache httpd + PHP + MySQL
PHP httpd
Our site
MySQL
Sample App - Feed Moby Dock
Credits: Originally done in Flask by acloud.guru, rewritten in PHP
Feed button and fed count
Random message
from database
Docker Store
Docker Store
Docker Store
“latest” tag is used by default
Our Files
$ ls -R
Dockerfile docker-compose.yml
./cert:
server.crt server.csr server.key
./conf:
000-default.conf apache2.conf default-ssl.conf php.ini
./database:
seed.sql
./public:
(...)
Docker image config files
HTTPS Cert
Apache and PHP
config files
SQL to create DB
Our Web App files
Dockerfile
FROM php:apache
RUN docker-php-ext-install mysqli
COPY conf/php.ini /usr/local/etc/php/
RUN a2enmod headers
RUN a2enmod rewrite
RUN a2enmod ssl
COPY cert/server.crt /etc/ssl/certs/
COPY cert/server.key /etc/ssl/certs/
COPY conf/000-default.conf /etc/apache2/sites-enabled/
COPY conf/default-ssl.conf /etc/apache2/sites-enabled/
COPY conf/apache2.conf /etc/apache2/
COPY public/ /var/www/html/
COPY .env /var/www/html/
Found in Docker Store PHP image’s description
Run apache commands to set up additional modules
Copy php.ini from image to container’s file system
Ref: Docker Command CMD vs RUN, COPY vs ADD
Copy SSL cert and httpd config files
Copy Web App files
docker-compose.yml
example_app_db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- '3306:3306'
volumes:
- ~/.docker-volumes/exampleapp/mysql/data:/var/lib/mysql
- ./database/seed.sql:/docker-entrypoint-initdb.d/seed.sql
example_app:
build: .
links:
- example_app_db
ports:
- '80:80'
- '443:443'
Variables found in MySQL image descriptionUse MySQL image
Link with MySQL image defined above
Map HTTP and HTTPS ports (local port:container port)
Map local volume to
container volume
and seed SQL file to
init directory
Read .env file with ${VAR_NAME}
Map local port 3306 to container
Build and Run
$ vi .env
MYSQL_ROOT_PASSWORD=password
MYSQL_DATABASE=exampleapp
MYSQL_USER=exampleapp
MYSQL_PASSWORD=password
$ docker-compose up
(...)
$ docker ps
CONTAINER ID IMAGE PORTS
bda700bcf1ab 3phpapp_example_app 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp
cf443ee159e7 mysql 0.0.0.0:3306->3306/tcp
Setting up environments with different configs,
you may:
● create multiple docker-compose.yml files
● create multiple .env files and use reference
Check port
mappings here
Docker Inspect
$ docker inspect [container ID]
(...)
"Env": [
"MYSQL_ROOT_PASSWORD=password",
"MYSQL_PASSWORD=password",
"MYSQL_USER=exampleapp",
"MYSQL_DATABASE=exampleapp",
(...)
$ docker exec -it [container ID] sh
#
Check whether environment
variables are loaded correctly
Run bash shell in a container
to check its file system
Check Seed Database
# mysql -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| exampleapp |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.02 sec)
mysql> use exampleapp
mysql> show tables;
+----------------------+
| Tables_in_exampleapp |
+----------------------+
| Feed |
| Messages |
+----------------------+
2 rows in set (0.00 sec)
mysql> select * from Messages;
+----------------------------------------------+
| message |
+----------------------------------------------+
| Thanks good sir. I am feeling quite healthy! |
| Thanks for the meal buddy. |
| Please stop feeding me. I am getting huge! |
+----------------------------------------------+
3 rows in set (0.00 sec)
Try it in https://localhost/
Click the button and hear
from Moby Dock
If you want to redo
this exercise, don’t
forget to remove
database files from
your local machine
(hint: check the yml)
What have we Achieved?
● Learnt the skills
○ To download and use Docker images
○ To compose our own Docker image
● Learnt the benefits
○ Lightweight
○ Experiment and use whatever technology fits best
○ Having multiple versions of tools without crashing (Java, Python 2 & 3, etc)
○ Automated deployment
○ Quickly and accurately set up environments for development, UAT, etc.
○ Scale easily
Scale easily? Really?
...or Actually the Same?
● What to do when adding new machines?
● How do containers discover each other?
● What happens if containers die?
● What if the host machine is down?
● What happens if 1 container is using excessive resources?
#GIFEE
● GIFEE - Google Infrastructure for Everyone Else
● Google starts over 2 billion containers per week
● Container Orchestration
● Docker Swarm, Kubernetes
● Cluster as a giant computer
Modern DevOps Architecture
Git Push Git Hook
Git / Source Ctrl. Jenkins / Continuous Integration Server
Static Tests
Unit Tests
Reporting
Docker Compose
Build
Docker Orchestration Docker Registry
Store
Docker Pull
...and they lived happily ever after.
Further Watchings & Readings
● Docker for DevOps - From Development to Production
MOOC by acloud.guru
● Scalable Microservices with Kubernetes
MOOC by Google and Udacity
● Shipping code with Docker + Kubernetes (Cantonese)
Recordings of 20 Jun 2016 Meetup @ OneSky
● ...and remember not to overkill: It’s the Future, It really is the future
Blog by CircleCI
learning:
with Thomas @ Search Investment Group
Slides & codes: http://bit.ly/thomasdocker

Contenu connexe

Tendances

Docker and containers - For Boston Docker Meetup Workshop in March 2015
Docker and containers - For Boston Docker Meetup Workshop in March 2015Docker and containers - For Boston Docker Meetup Workshop in March 2015
Docker and containers - For Boston Docker Meetup Workshop in March 2015
Jonas Rosland
 
Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9 Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9
Jérôme Petazzoni
 

Tendances (20)

Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Understand how docker works
Understand how docker worksUnderstand how docker works
Understand how docker works
 
Introduction to Containers and Docker
Introduction to Containers and DockerIntroduction to Containers and Docker
Introduction to Containers and Docker
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Basic docker for developer
Basic docker for developerBasic docker for developer
Basic docker for developer
 
Docker and the Container Ecosystem
Docker and the Container EcosystemDocker and the Container Ecosystem
Docker and the Container Ecosystem
 
Docker and containers - For Boston Docker Meetup Workshop in March 2015
Docker and containers - For Boston Docker Meetup Workshop in March 2015Docker and containers - For Boston Docker Meetup Workshop in March 2015
Docker and containers - For Boston Docker Meetup Workshop in March 2015
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9 Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9
 
Docker - introduction
Docker - introductionDocker - introduction
Docker - introduction
 
Docker and containers : Disrupting the virtual machine(VM)
Docker and containers : Disrupting the virtual machine(VM)Docker and containers : Disrupting the virtual machine(VM)
Docker and containers : Disrupting the virtual machine(VM)
 
Introduction to Docker and all things containers, Docker Meetup at RelateIQ
Introduction to Docker and all things containers, Docker Meetup at RelateIQIntroduction to Docker and all things containers, Docker Meetup at RelateIQ
Introduction to Docker and all things containers, Docker Meetup at RelateIQ
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Shipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with DockerShipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with Docker
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 

En vedette

Rabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_msRabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit MQ
 

En vedette (20)

Docker, From zero to hero
Docker, From zero to heroDocker, From zero to hero
Docker, From zero to hero
 
Easy applications deployment on OpenStack clouds
Easy applications deployment on OpenStack cloudsEasy applications deployment on OpenStack clouds
Easy applications deployment on OpenStack clouds
 
From zero to Docker
From zero to DockerFrom zero to Docker
From zero to Docker
 
Dockers zero to hero - (medium version)
Dockers zero to hero - (medium version)Dockers zero to hero - (medium version)
Dockers zero to hero - (medium version)
 
Docker zero
Docker zeroDocker zero
Docker zero
 
Docker: from zero to nonzero
Docker: from zero to nonzeroDocker: from zero to nonzero
Docker: from zero to nonzero
 
Rabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_msRabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_ms
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
From Zero to Hero - Nexinto
From Zero to Hero - NexintoFrom Zero to Hero - Nexinto
From Zero to Hero - Nexinto
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Docker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutesDocker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutes
 
Introduction To Docker
Introduction To DockerIntroduction To Docker
Introduction To Docker
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
From zero to hero with Docker
From zero to hero with DockerFrom zero to hero with Docker
From zero to hero with Docker
 
The DevOps Hero Toolkit: Nexus, Jenkins and Docker
The DevOps Hero Toolkit: Nexus, Jenkins and DockerThe DevOps Hero Toolkit: Nexus, Jenkins and Docker
The DevOps Hero Toolkit: Nexus, Jenkins and Docker
 
Zero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetesZero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetes
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
NetflixOSS and ZeroToDocker Talk
NetflixOSS and ZeroToDocker TalkNetflixOSS and ZeroToDocker Talk
NetflixOSS and ZeroToDocker Talk
 
Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment
 
29.05.2009, NEWSWIRE, Issue 71
29.05.2009, NEWSWIRE, Issue 7129.05.2009, NEWSWIRE, Issue 71
29.05.2009, NEWSWIRE, Issue 71
 

Similaire à Learning Docker with Thomas

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
 
Lecture eight to be introduced in class.
Lecture eight to be introduced in class.Lecture eight to be introduced in class.
Lecture eight to be introduced in class.
nigamsajal14
 

Similaire à Learning Docker with Thomas (20)

Develop with docker 2014 aug
Develop with docker 2014 augDevelop with docker 2014 aug
Develop with docker 2014 aug
 
Docker in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday 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 Introduction.pdf
Docker Introduction.pdfDocker Introduction.pdf
Docker Introduction.pdf
 
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2
 
Lecture eight to be introduced in class.
Lecture eight to be introduced in class.Lecture eight to be introduced in class.
Lecture eight to be introduced in class.
 
docker.pdf
docker.pdfdocker.pdf
docker.pdf
 
Running the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerRunning the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker Container
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
時代在變 Docker 要會:台北 Docker 一日入門篇
時代在變 Docker 要會:台北 Docker 一日入門篇時代在變 Docker 要會:台北 Docker 一日入門篇
時代在變 Docker 要會:台北 Docker 一日入門篇
 
O'Reilly Software Architecture Conference London 2017: Building Resilient Mic...
O'Reilly Software Architecture Conference London 2017: Building Resilient Mic...O'Reilly Software Architecture Conference London 2017: Building Resilient Mic...
O'Reilly Software Architecture Conference London 2017: Building Resilient Mic...
 
Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020
 
Docker in Action
Docker in ActionDocker in Action
Docker in Action
 
Présentation de Docker
Présentation de DockerPrésentation de Docker
Présentation de Docker
 
Containers without docker | DevNation Tech Talk
Containers without docker | DevNation Tech TalkContainers without docker | DevNation Tech Talk
Containers without docker | DevNation Tech Talk
 
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2
 
How to _docker
How to _dockerHow to _docker
How to _docker
 
Docking with Docker
Docking with DockerDocking with Docker
Docking with Docker
 
Docker @ Atlogys
Docker @ AtlogysDocker @ Atlogys
Docker @ Atlogys
 
Streamline your development environment with docker
Streamline your development environment with dockerStreamline your development environment with docker
Streamline your development environment with docker
 

Dernier

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
 

Dernier (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Learning Docker with Thomas

  • 1. learning: with Thomas @ Search Investment Group Slides & codes: http://bit.ly/thomasdocker
  • 2. Ref: 8 surprising facts about real docker adoption
  • 5. Benefits ● Lightweight ● Experiment and use whatever technology fits best ● Having multiple versions of tools without crashing (Java, Python 2 & 3, etc) ● Automated deployment ● Quickly and accurately set up environments for DEV, UAT, etc. ● Scale easily
  • 6. Today’s Demo ● Install Docker ● Download and run a Hello World Docker image ● Compose our own Hello World Docker Image ● Compose our own Docker Image that contains a PHP-MySQL application
  • 12. Hello World $ docker --version Docker version 1.13.0, build 49bf474 $ docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world 78445dd45222: Pull complete Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 $ docker run hello-world Hello from Docker! (...) Ref for our “SSL Deep Inspection”: Docker behind proxy that changes ssl certificate
  • 13. Basic Docker Commands $ docker images (list the images you pulled) $ docker ps (list the running containers) $ docker ps -a (list all containers, including exited) $ docker [command] --help (check the documentation) $ docker rmi [image ID] (remove the image by the associated ID - you don’t have to type in full ID!) $ docker stop [container ID] (stop the running container by the ID) $ docker rm [container ID] (stop and remove the container from the ps -a list) $ docker ps -aq | xargs docker rm (stop and remove all containers)
  • 14. Build our own Hello World Python container Our hello-world container
  • 15. Hello World in Python $ echo 'print("Hello from Thomas")' > app.py $ cat app.py print("Hello from Thomas") $ python app.py Hello from Thomas
  • 17. Dockerfile & docker-compose.yml $ vi Dockerfile FROM python MAINTAINER Thomas Tong <hello@thomastong.me> COPY app.py app.py CMD python app.py $ vi docker-compose.yml helloworld: build: . Describes the necessary steps to build the container Describes the container in its running state (environment variables, dependencies to others containers, etc) Ref: Docker Compose vs. Dockerfile
  • 18. Compose a Docker Image $ ls Dockerfile app.py docker-compose.yml $ docker-compose build Building helloworld Step 1/4 : FROM python latest: Pulling from library/python 5040bd298390: Pull complete fce5728aad85: Pull complete 76610ec20bf5: Pull complete 52f3db4b5710: Pull complete 45b2a7e03e44: Pull complete 75ef15b2048b: Pull complete e41da2f0bac3: Pull complete Digest: sha256:cba517218b4342514e000557e6e9100018f980cda866420 ff61bfa9628ced1dc Status: Downloaded newer image for python:latest ---> 775dae9b960e Step 2/4 : MAINTAINER Thomas Tong <hello@thomastong.me> ---> Running in b257c26e3b5e ---> b6a9ca588053 Removing intermediate container b257c26e3b5e Step 3/4 : COPY app.py app.py ---> c30eb29c8920 Removing intermediate container 5c74e320839d Step 4/4 : CMD python app.py ---> Running in 5c2295d819ad ---> b54de6654b62 Removing intermediate container 5c2295d819ad Successfully built b54de6654b62
  • 19. Run the Docker Image $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE 2helloworld_helloworld latest b54de6654b62 7 minutes ago 687 MB python latest 775dae9b960e 7 minutes ago 687 MB $ docker run [image name/ID] Hello from Thomas $ docker-compose up Creating 2helloworld_helloworld_1 Attaching to 2helloworld_helloworld_1 helloworld_1 | Hello from Thomas 2helloworld_helloworld_1 exited with code 0 You can only use this after building the image Build and start according to the Dockerfile and docker-compose.yml, good for development
  • 20. Apache httpd + PHP + MySQL PHP httpd Our site MySQL
  • 21. Sample App - Feed Moby Dock Credits: Originally done in Flask by acloud.guru, rewritten in PHP Feed button and fed count Random message from database
  • 24. Docker Store “latest” tag is used by default
  • 25. Our Files $ ls -R Dockerfile docker-compose.yml ./cert: server.crt server.csr server.key ./conf: 000-default.conf apache2.conf default-ssl.conf php.ini ./database: seed.sql ./public: (...) Docker image config files HTTPS Cert Apache and PHP config files SQL to create DB Our Web App files
  • 26. Dockerfile FROM php:apache RUN docker-php-ext-install mysqli COPY conf/php.ini /usr/local/etc/php/ RUN a2enmod headers RUN a2enmod rewrite RUN a2enmod ssl COPY cert/server.crt /etc/ssl/certs/ COPY cert/server.key /etc/ssl/certs/ COPY conf/000-default.conf /etc/apache2/sites-enabled/ COPY conf/default-ssl.conf /etc/apache2/sites-enabled/ COPY conf/apache2.conf /etc/apache2/ COPY public/ /var/www/html/ COPY .env /var/www/html/ Found in Docker Store PHP image’s description Run apache commands to set up additional modules Copy php.ini from image to container’s file system Ref: Docker Command CMD vs RUN, COPY vs ADD Copy SSL cert and httpd config files Copy Web App files
  • 27. docker-compose.yml example_app_db: image: mysql environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_DATABASE: ${MYSQL_DATABASE} MYSQL_USER: ${MYSQL_USER} MYSQL_PASSWORD: ${MYSQL_PASSWORD} ports: - '3306:3306' volumes: - ~/.docker-volumes/exampleapp/mysql/data:/var/lib/mysql - ./database/seed.sql:/docker-entrypoint-initdb.d/seed.sql example_app: build: . links: - example_app_db ports: - '80:80' - '443:443' Variables found in MySQL image descriptionUse MySQL image Link with MySQL image defined above Map HTTP and HTTPS ports (local port:container port) Map local volume to container volume and seed SQL file to init directory Read .env file with ${VAR_NAME} Map local port 3306 to container
  • 28. Build and Run $ vi .env MYSQL_ROOT_PASSWORD=password MYSQL_DATABASE=exampleapp MYSQL_USER=exampleapp MYSQL_PASSWORD=password $ docker-compose up (...) $ docker ps CONTAINER ID IMAGE PORTS bda700bcf1ab 3phpapp_example_app 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp cf443ee159e7 mysql 0.0.0.0:3306->3306/tcp Setting up environments with different configs, you may: ● create multiple docker-compose.yml files ● create multiple .env files and use reference Check port mappings here
  • 29. Docker Inspect $ docker inspect [container ID] (...) "Env": [ "MYSQL_ROOT_PASSWORD=password", "MYSQL_PASSWORD=password", "MYSQL_USER=exampleapp", "MYSQL_DATABASE=exampleapp", (...) $ docker exec -it [container ID] sh # Check whether environment variables are loaded correctly Run bash shell in a container to check its file system
  • 30. Check Seed Database # mysql -u root -p mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | exampleapp | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.02 sec) mysql> use exampleapp mysql> show tables; +----------------------+ | Tables_in_exampleapp | +----------------------+ | Feed | | Messages | +----------------------+ 2 rows in set (0.00 sec) mysql> select * from Messages; +----------------------------------------------+ | message | +----------------------------------------------+ | Thanks good sir. I am feeling quite healthy! | | Thanks for the meal buddy. | | Please stop feeding me. I am getting huge! | +----------------------------------------------+ 3 rows in set (0.00 sec)
  • 31. Try it in https://localhost/ Click the button and hear from Moby Dock If you want to redo this exercise, don’t forget to remove database files from your local machine (hint: check the yml)
  • 32. What have we Achieved? ● Learnt the skills ○ To download and use Docker images ○ To compose our own Docker image ● Learnt the benefits ○ Lightweight ○ Experiment and use whatever technology fits best ○ Having multiple versions of tools without crashing (Java, Python 2 & 3, etc) ○ Automated deployment ○ Quickly and accurately set up environments for development, UAT, etc. ○ Scale easily Scale easily? Really?
  • 33. ...or Actually the Same? ● What to do when adding new machines? ● How do containers discover each other? ● What happens if containers die? ● What if the host machine is down? ● What happens if 1 container is using excessive resources?
  • 34. #GIFEE ● GIFEE - Google Infrastructure for Everyone Else ● Google starts over 2 billion containers per week ● Container Orchestration ● Docker Swarm, Kubernetes ● Cluster as a giant computer
  • 35. Modern DevOps Architecture Git Push Git Hook Git / Source Ctrl. Jenkins / Continuous Integration Server Static Tests Unit Tests Reporting Docker Compose Build Docker Orchestration Docker Registry Store Docker Pull
  • 36. ...and they lived happily ever after.
  • 37. Further Watchings & Readings ● Docker for DevOps - From Development to Production MOOC by acloud.guru ● Scalable Microservices with Kubernetes MOOC by Google and Udacity ● Shipping code with Docker + Kubernetes (Cantonese) Recordings of 20 Jun 2016 Meetup @ OneSky ● ...and remember not to overkill: It’s the Future, It really is the future Blog by CircleCI
  • 38. learning: with Thomas @ Search Investment Group Slides & codes: http://bit.ly/thomasdocker