SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Docker workshop
Workshop about the basic usage of Docker
Nicolas DEGARDIN <ndegardin@tribalnova.com>
Summary
1. Preparation
2. The ping example
3. Container
4. Port publishing
5. Volume share
6. Environment variables
7. Dockerfile
8. Docker push
9. Linked container
10. Linked container Dockerfile
11. Vagrant provisioning
Preparation
Needed:
•Virtual Box
•Vagrant
•ZIP workshop file tuto.zip
(if unavailable, the archive is here: https://hmhco.box.com/docker-tuto)
•Nothing should run on ports 80 and 81 of the host machine
1. Extract the ZIP file in a directory
2. Optionally configure PHPStorm/Webstorm vagrant settings
3. Run vagrant up in the tutorial directory
4. Run vagrant ssh in the tutorial directory
The ping example
Run a container that echoes a ping
•Based on phusion/baseimage:0.9.15
•Try to see what happen with docker images, docker ps, docker logs
•When in background, try to play with docker attach
•Manipulate docker rm, docker kill, docker start, docker stop
•Documentation
–Commands docker and docker <instruction> --help
–https://docs.docker.com/reference/commandline/cli/
1. Run a ping on www.google.ca in a container
2. Restart the container and stop it
3. Run a ping on www.google.ca in a container as a daemon
The ping example
(docker search phusion)
(docker pull phusion/baseimage:0.9.15)
docker run --name test phusion/baseimage:0.9.15 ping www.google.fr
<CTRL+C>
docker images
docker ps
docker ps –a
docker start test
docker logs -f test
docker ps
docker attach test
<CTRL+C>
docker stop test
docker rm test
docker ps –a
docker images
docker run -d --name test phusion/baseimage:0.9.15 ping www.google.fr
docker ps
docker logs -f test
docker rm test
docker rm -f test (ou docker stop test puis docker rm ou docker kill test)
docker ps -a
(docker rmi phusion/baseimage:0.9.15)
Container
Run a container, install a nodeJS server onto it, and commit it:
•Based on tribalnova/baseimage-ubuntu1404
1. Run a bash command in the container, named nodejs
1. Inside it, run the script /var/docker/install-devtools.sh on it
2. Launch zsh
3. Install nodejs-legacy and npm packages
4. Create the dir /var/www/tuto and create a test.js file inside it (given file)
5. Test nodejs locally
6. Exit the container
2. Commit the container new image as tribalnova/nodejs
3. Show the history of tribalnova/nodejs
Container
var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {
'Content-Type': 'text/plain'
});
response.end('Hello');
}).listen(80);
console.log("Server running");
test.js
Container
(docker pull tribalnova/baseimage-ubuntu1404)
docker run -ti --name nodejs tribalnova/baseimage-ubuntu1404 bash
#/var/docker/install-devtools.sh
#rm /var/docker/install-devtools.sh
#zsh
#apt-get update
#apt-get install nodejs-legacy npm
#mkdir /var/www
#mkdir /var/www/tuto
#cd /var/www/tuto
#npm install http
#vi test.js
#node test.js &
#curl 127.0.0.1
<CTRL+P> <CTRL+Q>
docker commit nodejs tribalnova/nodejs
docker history tribalnova/nodejs
Port publishing
Run the nodeJS container by forwarding its port 80 the host:
1. Try to reach the port 80
2. Inspect the current ndoeJS container
3. Remove the nodeJS container
4. Run the nodeJS container test.js file, mapping the port 80
5. Inspect the nodeJS container
Port publishing
docker inspect nodejs
curl <IP>
docker ps
docker images
docker rm -f nodejs
docker run -d -p 80:80 --name nodejs tribalnova/nodejs node
/var/www/tuto/test.js
docker logs nodejs
docker inspect nodejs
curl <IP>
Volume share
Run the nodeJS container by sharing its project volume:
1. Remove the previous nodejs container
2. Run it again by sharing /var/www/tuto with the host
3. Try to reach its port 80
4. Remove the nodeJS container
5. Launch it by mapping the port 80
6. Retry to reach its port 80
Volume share
docker rm -f nodejs
vi /var/www/tuto/test.js
docker run -d -p 80:80 -v /var/www/tuto:/var/www/tuto --name nodejs
tribalnova/nodejs node /var/www/tuto/test.js
docker logs nodejs
docker inspect nodejs
curl <IP>
Environment variable
Run the nodeJS container and pass an environment variable:
1. Remove the previous nodejs container
2. Run it again by passing a variable TEST=TUTO to it
3. Inspect the container
4. Connect to it
5. Display the environment variable
6. Remove the container
Environment variable
docker rm -f nodejs
docker run -d -p 80:80 -e TEST=TUTO -v /var/www/tuto:/var/www/tuto --
name nodejs tribalnova/nodejs node /var/www/tuto/test.js
docker inspect nodejs
docker exec -ti nodejs zsh
#env
#exit
docker rm -f nodejs
Dockerfile
Run the nodeJS container from Dockerfile images
Documentation : https://docs.docker.com/reference/builder/
1. Create a Dockerfile image with only a nodeJS server installed, in the
directory docker/nodejs
2. Build it, and name the image tribalnova/nodejs
3. Create a Dockerfile image that inherits from the image tribalnova/nodejs,
that embeds the test.js file, and launch it through nodeJS as a default
command, in the directory docker/tuto
4. Build it and name the image tribalnova/tuto
5. Run in a container the image tribalnova/tuto, by sharing the volume and
publishing the port as before
6. Test it
Dockerfile
cd docker
mkdir nodejs
cd nodejs
vi Dockerfile
docker build -t tribalnova/nodejs .
cd ..
mkdir tuto
cd tuto
vi test.js
vi Dockerfile
docker build -t tribalnova/tuto .
docker run --rm -ti -p 80:80 tribalnova/tuto
docker run --name nodejs -d -v /var/www/tuto:/var/www/tuto -p 80:80 tribalnova/tuto
vi /var/www/tuto/test.js <change the hello world message>
docker stop nodejs
docker start nodejs
FROM tribalnova/baseimage-ubuntu1404
MAINTAINER me
RUN apt-get update && apt-get install -y nodejs-
legacy npm
RUN /var/docker/install-devtools.sh && rm
/var/docker/install-devtools.sh
nodejs/Dockerfile
FROM tribalnova/nodejs
MAINTAINER me
ADD test.js /var/www/tuto/test.js
WORKDIR /var/www/tuto
EXPOSE 80
CMD node /var/www/tuto/test.js
tuto/Dockerfile
Docker push
Push the docker images to Dockerhub
1. Login
2. Push tribalnova/nodejs
3. Push tribalnova/tuto
4. Logout
Docker push
docker login
docker push tribalnova/nodejs
docker search nodejs
docker logout
docker search nodejs
Container linking
Launch a mongoDB container and create a nodeJS container with an
application that connects to it
1. Find and launch the mongoDB official container
2. Run the container tribalnova/tuto in daemon, by linking the mongo
container to it
3. Inspect the container
4. Execute a zsh command on it
1. Display the environment variables
2. Test the mongoDB connection
3. Install the nodeJS mongodb package with npm
4. Create the test2.js file (provided file)
5. Commit this container image as tribalnova/tuto2
6. Run it on the port 81 in rm mode, launching test2.js through nodeJS
Container linking
var http = require("http");
var MongoClient = require('mongodb').MongoClient
var url = 'mongodb://mongo:27017/tuto';
http.createServer(function (request, response) {
response.writeHead(200, {
'Content-Type': 'text/plain'
});
MongoClient.connect(url, function(err, db) {
if(err) throw err;
var collection = db.collection('samples');
collection.insert([
{'hello' : 'world'}, {'et' : 'cetera'}, {'et' : {'cetera':'et cetera'}}
], {w:1}, function(err, result) {
collection.find().toArray(function(err, docs) {
response.end(JSON.stringify(docs));
});
});
});
}).listen(80);
console.log("Server running");
test2.js
Container linking
docker search mongo
docker run -d --name mongo mongo
docker run --name nodejs --link mongo:mongo -d -p 80:80 tribalnova/tuto
docker inspect nodejs
docker exec -ti nodejs zsh
#env
#more /etc/hosts
#nc -zv mongo 27017
#cd /var/www/tuto
#npm install mongodb
#vi test2.js
#exit
docker commit nodejs tribalnova/tuto2
docker run --rm --link mongo:mongo -p 81:80 tribalnova/tuto2 node test2.js
Linked container Dockerfile
Create a Dockerfile for a container that embeds the two nodeJS projects
1. Create a docker/tuto2 directory
2. Put the project files inside
3. Create a Dockerfile with:
1. An entrypoint that launch the node executable
2. The container must launch test.js by default
4. Build the image, naming it tribalnova/tuto2
5. Run a container with the default command, with the rm option
6. Run a container with node executing test2.js, with the rm option
Linked container Dockerfile
cd docker
mkdir tuto2
<copy files test.js and test2.js inside>
vi Dockerfile
docker build -t tribalnova/tuto2 .
docker run --rm --link mongo:mongo –p 80:80 tribalnova/tuto2
<CTRL+C>
docker run --rm --link mongo:mongo –p 80:80 tribalnova/tuto2 test2.js
FROM tribalnova/nodejs
MAINTAINER me
RUN npm install mongodb
ADD test.js /var/www/tuto/test.js
ADD test2.js /var/www/tuto/test2.js
WORKDIR /var/www/tuto
EXPOSE 80
ENTRYPOINT ["node"]
CMD ["test.js"]
tuto2/Dockerfile
Vagrant provisioner
Modify the Vagrant file to build and launch the containers upon provisioning.
Documentation: http://docs.vagrantup.com/v2/provisioning/docker.html
1. Clear the containers and images
2. Alter Vagrantfile
3. Run the provising
Vagrant provisioner
docker ps -qa | xargs docker rm -f
docker images -q | xargs docker rmi –f
ON THE HOST MACHINE:
<insert the Vagrantfile docker section>
vagrant provision
config.vm.provision "docker" do |d|
d.run "mongo",
daemonize: true,
args: "--name mongo"
d.build_image "./docker/nodejs",
args: "-t tribalnova/nodejs"
d.build_image "./docker/tuto",
args: "-t tribalnova/tuto"
d.build_image "./docker/tuto2",
args: "-t tribalnova/tuto2"
d.run "tribalnova/tuto",
daemonize: true,
args: "--name tuto 
--link mongo:mongo 
-p 80:80"
d.run "tribalnova/tuto2",
daemonize: true,
args: "--name tuto2 
--link mongo:mongo 
-p 81:80"
end
Vagrantfile
Docker workshop for basic usage, container linking and Vagrant provisioning

Weitere ähnliche Inhalte

Was ist angesagt?

Lessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containersLessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containersBen Hall
 
Lessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containersLessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containersBen Hall
 
Py conkr 20150829_docker-python
Py conkr 20150829_docker-pythonPy conkr 20150829_docker-python
Py conkr 20150829_docker-pythonEric Ahn
 
Reproducibility of computational workflows is automated using continuous anal...
Reproducibility of computational workflows is automated using continuous anal...Reproducibility of computational workflows is automated using continuous anal...
Reproducibility of computational workflows is automated using continuous anal...Kento Aoyama
 
PuppetCamp SEA 1 - Use of Puppet
PuppetCamp SEA 1 - Use of PuppetPuppetCamp SEA 1 - Use of Puppet
PuppetCamp SEA 1 - Use of PuppetWalter Heck
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012Carlos Sanchez
 
Gr8conf EU 2018 - Bring you infrastructure under control with Infrastructor
Gr8conf EU 2018 - Bring you infrastructure under control with InfrastructorGr8conf EU 2018 - Bring you infrastructure under control with Infrastructor
Gr8conf EU 2018 - Bring you infrastructure under control with InfrastructorStanislav Tiurikov
 
From Dev to DevOps
From Dev to DevOpsFrom Dev to DevOps
From Dev to DevOpsAgile Spain
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)Soshi Nemoto
 
Docker - from development to production (PHPNW 2017-09-05)
Docker - from development to production (PHPNW 2017-09-05)Docker - from development to production (PHPNW 2017-09-05)
Docker - from development to production (PHPNW 2017-09-05)Toby Griffiths
 
Docker - container and lightweight virtualization
Docker - container and lightweight virtualization Docker - container and lightweight virtualization
Docker - container and lightweight virtualization Sim Janghoon
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Cosimo Streppone
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Jérôme Petazzoni
 
CoreOS + Kubernetes @ All Things Open 2015
CoreOS + Kubernetes @ All Things Open 2015CoreOS + Kubernetes @ All Things Open 2015
CoreOS + Kubernetes @ All Things Open 2015Brandon Philips
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Soshi Nemoto
 
Docker command
Docker commandDocker command
Docker commandEric Ahn
 
Containers: What are they, Really?
Containers: What are they, Really?Containers: What are they, Really?
Containers: What are they, Really?Sneha Inguva
 

Was ist angesagt? (20)

Lessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containersLessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containers
 
Lessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containersLessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containers
 
Py conkr 20150829_docker-python
Py conkr 20150829_docker-pythonPy conkr 20150829_docker-python
Py conkr 20150829_docker-python
 
Reproducibility of computational workflows is automated using continuous anal...
Reproducibility of computational workflows is automated using continuous anal...Reproducibility of computational workflows is automated using continuous anal...
Reproducibility of computational workflows is automated using continuous anal...
 
PuppetCamp SEA 1 - Use of Puppet
PuppetCamp SEA 1 - Use of PuppetPuppetCamp SEA 1 - Use of Puppet
PuppetCamp SEA 1 - Use of Puppet
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
Gr8conf EU 2018 - Bring you infrastructure under control with Infrastructor
Gr8conf EU 2018 - Bring you infrastructure under control with InfrastructorGr8conf EU 2018 - Bring you infrastructure under control with Infrastructor
Gr8conf EU 2018 - Bring you infrastructure under control with Infrastructor
 
From Dev to DevOps
From Dev to DevOpsFrom Dev to DevOps
From Dev to DevOps
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
 
Docker - from development to production (PHPNW 2017-09-05)
Docker - from development to production (PHPNW 2017-09-05)Docker - from development to production (PHPNW 2017-09-05)
Docker - from development to production (PHPNW 2017-09-05)
 
Docker - container and lightweight virtualization
Docker - container and lightweight virtualization Docker - container and lightweight virtualization
Docker - container and lightweight virtualization
 
ABCs of docker
ABCs of dockerABCs of docker
ABCs of docker
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...
 
CoreOS + Kubernetes @ All Things Open 2015
CoreOS + Kubernetes @ All Things Open 2015CoreOS + Kubernetes @ All Things Open 2015
CoreOS + Kubernetes @ All Things Open 2015
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)
 
Light my-fuse
Light my-fuseLight my-fuse
Light my-fuse
 
Docker command
Docker commandDocker command
Docker command
 
Containers: What are they, Really?
Containers: What are they, Really?Containers: What are they, Really?
Containers: What are they, Really?
 

Andere mochten auch

Venture Capital - An Introduction
Venture Capital - An IntroductionVenture Capital - An Introduction
Venture Capital - An IntroductionJanis Zech
 
Docker - Containervirtualisierung leichtgemacht
Docker - Containervirtualisierung leichtgemachtDocker - Containervirtualisierung leichtgemacht
Docker - Containervirtualisierung leichtgemachtB1 Systems GmbH
 
Visualising Basic Concepts of Docker
Visualising Basic Concepts of Docker Visualising Basic Concepts of Docker
Visualising Basic Concepts of Docker vishnu rao
 
Introduction to Desired State Configuration (DSC)
Introduction to Desired State Configuration (DSC)Introduction to Desired State Configuration (DSC)
Introduction to Desired State Configuration (DSC)Jeffery Hicks
 
Rootlinux17: An introduction to Xen Project Virtualisation
Rootlinux17:  An introduction to Xen Project VirtualisationRootlinux17:  An introduction to Xen Project Virtualisation
Rootlinux17: An introduction to Xen Project VirtualisationThe Linux Foundation
 
Basic docker for developer
Basic docker for developerBasic docker for developer
Basic docker for developerWeerayut Hongsa
 
Docker Einführung @GPN15
Docker Einführung @GPN15Docker Einführung @GPN15
Docker Einführung @GPN15m1no
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and PracticesAnand Bagmar
 
Landscape Line Drawings (sketch examples)
Landscape Line Drawings (sketch examples)Landscape Line Drawings (sketch examples)
Landscape Line Drawings (sketch examples)Frank Curkovic
 
Introduction to Cognitive Ergonomics
Introduction to Cognitive ErgonomicsIntroduction to Cognitive Ergonomics
Introduction to Cognitive ErgonomicsDun Huang
 
New Amazing Things about AngularJS 2.0
New Amazing Things about AngularJS 2.0New Amazing Things about AngularJS 2.0
New Amazing Things about AngularJS 2.0Mike Taylor
 
Product Marketing Framework for Product or Service Launch
Product Marketing Framework for Product or Service LaunchProduct Marketing Framework for Product or Service Launch
Product Marketing Framework for Product or Service LaunchJanet Jaiswal
 

Andere mochten auch (14)

Venture Capital - An Introduction
Venture Capital - An IntroductionVenture Capital - An Introduction
Venture Capital - An Introduction
 
Docker - Containervirtualisierung leichtgemacht
Docker - Containervirtualisierung leichtgemachtDocker - Containervirtualisierung leichtgemacht
Docker - Containervirtualisierung leichtgemacht
 
Visualising Basic Concepts of Docker
Visualising Basic Concepts of Docker Visualising Basic Concepts of Docker
Visualising Basic Concepts of Docker
 
Introduction to Desired State Configuration (DSC)
Introduction to Desired State Configuration (DSC)Introduction to Desired State Configuration (DSC)
Introduction to Desired State Configuration (DSC)
 
Rootlinux17: An introduction to Xen Project Virtualisation
Rootlinux17:  An introduction to Xen Project VirtualisationRootlinux17:  An introduction to Xen Project Virtualisation
Rootlinux17: An introduction to Xen Project Virtualisation
 
What is Docker
What is DockerWhat is Docker
What is Docker
 
Basic docker for developer
Basic docker for developerBasic docker for developer
Basic docker for developer
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Docker Einführung @GPN15
Docker Einführung @GPN15Docker Einführung @GPN15
Docker Einführung @GPN15
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and Practices
 
Landscape Line Drawings (sketch examples)
Landscape Line Drawings (sketch examples)Landscape Line Drawings (sketch examples)
Landscape Line Drawings (sketch examples)
 
Introduction to Cognitive Ergonomics
Introduction to Cognitive ErgonomicsIntroduction to Cognitive Ergonomics
Introduction to Cognitive Ergonomics
 
New Amazing Things about AngularJS 2.0
New Amazing Things about AngularJS 2.0New Amazing Things about AngularJS 2.0
New Amazing Things about AngularJS 2.0
 
Product Marketing Framework for Product or Service Launch
Product Marketing Framework for Product or Service LaunchProduct Marketing Framework for Product or Service Launch
Product Marketing Framework for Product or Service Launch
 

Ähnlich wie Docker workshop for basic usage, container linking and Vagrant provisioning

手把手帶你學Docker 03042017
手把手帶你學Docker 03042017手把手帶你學Docker 03042017
手把手帶你學Docker 03042017Paul Chao
 
Docker workshop 0507 Taichung
Docker workshop 0507 Taichung Docker workshop 0507 Taichung
Docker workshop 0507 Taichung Paul Chao
 
手把手帶你學 Docker 入門篇
手把手帶你學 Docker 入門篇手把手帶你學 Docker 入門篇
手把手帶你學 Docker 入門篇Philip Zheng
 
時代在變 Docker 要會:台北 Docker 一日入門篇
時代在變 Docker 要會:台北 Docker 一日入門篇時代在變 Docker 要會:台北 Docker 一日入門篇
時代在變 Docker 要會:台北 Docker 一日入門篇Philip Zheng
 
Docker workshop
Docker workshopDocker workshop
Docker workshopEvans Ye
 
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 ContainerGuido Schmutz
 
Dockerizing a Symfony2 application
Dockerizing a Symfony2 applicationDockerizing a Symfony2 application
Dockerizing a Symfony2 applicationRoman Rodomansky
 
Learn docker in 90 minutes
Learn docker in 90 minutesLearn docker in 90 minutes
Learn docker in 90 minutesLarry Cai
 
Docker workshop DevOpsDays Amsterdam 2014
Docker workshop DevOpsDays Amsterdam 2014Docker workshop DevOpsDays Amsterdam 2014
Docker workshop DevOpsDays Amsterdam 2014Pini Reznik
 
Powercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptxPowercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptxIgnacioTamayo2
 
Docker Introductory workshop
Docker Introductory workshopDocker Introductory workshop
Docker Introductory workshopRuncy Oommen
 
桃園市教育局Docker技術入門與實作
桃園市教育局Docker技術入門與實作桃園市教育局Docker技術入門與實作
桃園市教育局Docker技術入門與實作Philip Zheng
 
Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Ben Hall
 
Docker for mere mortals
Docker for mere mortalsDocker for mere mortals
Docker for mere mortalsHenryk Konsek
 
Docker in Action
Docker in ActionDocker in Action
Docker in ActionSimon Su
 
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context ConstraintsAlessandro Arrichiello
 

Ähnlich wie Docker workshop for basic usage, container linking and Vagrant provisioning (20)

手把手帶你學Docker 03042017
手把手帶你學Docker 03042017手把手帶你學Docker 03042017
手把手帶你學Docker 03042017
 
Docker workshop 0507 Taichung
Docker workshop 0507 Taichung Docker workshop 0507 Taichung
Docker workshop 0507 Taichung
 
手把手帶你學 Docker 入門篇
手把手帶你學 Docker 入門篇手把手帶你學 Docker 入門篇
手把手帶你學 Docker 入門篇
 
時代在變 Docker 要會:台北 Docker 一日入門篇
時代在變 Docker 要會:台北 Docker 一日入門篇時代在變 Docker 要會:台北 Docker 一日入門篇
時代在變 Docker 要會:台北 Docker 一日入門篇
 
Docker workshop
Docker workshopDocker workshop
Docker workshop
 
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
 
Dockerizing a Symfony2 application
Dockerizing a Symfony2 applicationDockerizing a Symfony2 application
Dockerizing a Symfony2 application
 
How to _docker
How to _dockerHow to _docker
How to _docker
 
Learn docker in 90 minutes
Learn docker in 90 minutesLearn docker in 90 minutes
Learn docker in 90 minutes
 
Docker workshop DevOpsDays Amsterdam 2014
Docker workshop DevOpsDays Amsterdam 2014Docker workshop DevOpsDays Amsterdam 2014
Docker workshop DevOpsDays Amsterdam 2014
 
Powercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptxPowercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptx
 
Docker Introductory workshop
Docker Introductory workshopDocker Introductory workshop
Docker Introductory workshop
 
桃園市教育局Docker技術入門與實作
桃園市教育局Docker技術入門與實作桃園市教育局Docker技術入門與實作
桃園市教育局Docker技術入門與實作
 
Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)
 
Docker for mere mortals
Docker for mere mortalsDocker for mere mortals
Docker for mere mortals
 
Docker in Action
Docker in ActionDocker in Action
Docker in Action
 
Docker研習營
Docker研習營Docker研習營
Docker研習營
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
 
Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter Pack
 

Kürzlich hochgeladen

Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirtrahman018755
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 

Kürzlich hochgeladen (20)

Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 

Docker workshop for basic usage, container linking and Vagrant provisioning

  • 1. Docker workshop Workshop about the basic usage of Docker Nicolas DEGARDIN <ndegardin@tribalnova.com>
  • 2. Summary 1. Preparation 2. The ping example 3. Container 4. Port publishing 5. Volume share 6. Environment variables 7. Dockerfile 8. Docker push 9. Linked container 10. Linked container Dockerfile 11. Vagrant provisioning
  • 3. Preparation Needed: •Virtual Box •Vagrant •ZIP workshop file tuto.zip (if unavailable, the archive is here: https://hmhco.box.com/docker-tuto) •Nothing should run on ports 80 and 81 of the host machine 1. Extract the ZIP file in a directory 2. Optionally configure PHPStorm/Webstorm vagrant settings 3. Run vagrant up in the tutorial directory 4. Run vagrant ssh in the tutorial directory
  • 4. The ping example Run a container that echoes a ping •Based on phusion/baseimage:0.9.15 •Try to see what happen with docker images, docker ps, docker logs •When in background, try to play with docker attach •Manipulate docker rm, docker kill, docker start, docker stop •Documentation –Commands docker and docker <instruction> --help –https://docs.docker.com/reference/commandline/cli/ 1. Run a ping on www.google.ca in a container 2. Restart the container and stop it 3. Run a ping on www.google.ca in a container as a daemon
  • 5. The ping example (docker search phusion) (docker pull phusion/baseimage:0.9.15) docker run --name test phusion/baseimage:0.9.15 ping www.google.fr <CTRL+C> docker images docker ps docker ps –a docker start test docker logs -f test docker ps docker attach test <CTRL+C> docker stop test docker rm test docker ps –a docker images docker run -d --name test phusion/baseimage:0.9.15 ping www.google.fr docker ps docker logs -f test docker rm test docker rm -f test (ou docker stop test puis docker rm ou docker kill test) docker ps -a (docker rmi phusion/baseimage:0.9.15)
  • 6. Container Run a container, install a nodeJS server onto it, and commit it: •Based on tribalnova/baseimage-ubuntu1404 1. Run a bash command in the container, named nodejs 1. Inside it, run the script /var/docker/install-devtools.sh on it 2. Launch zsh 3. Install nodejs-legacy and npm packages 4. Create the dir /var/www/tuto and create a test.js file inside it (given file) 5. Test nodejs locally 6. Exit the container 2. Commit the container new image as tribalnova/nodejs 3. Show the history of tribalnova/nodejs
  • 7. Container var http = require("http"); http.createServer(function (request, response) { response.writeHead(200, { 'Content-Type': 'text/plain' }); response.end('Hello'); }).listen(80); console.log("Server running"); test.js
  • 8. Container (docker pull tribalnova/baseimage-ubuntu1404) docker run -ti --name nodejs tribalnova/baseimage-ubuntu1404 bash #/var/docker/install-devtools.sh #rm /var/docker/install-devtools.sh #zsh #apt-get update #apt-get install nodejs-legacy npm #mkdir /var/www #mkdir /var/www/tuto #cd /var/www/tuto #npm install http #vi test.js #node test.js & #curl 127.0.0.1 <CTRL+P> <CTRL+Q> docker commit nodejs tribalnova/nodejs docker history tribalnova/nodejs
  • 9. Port publishing Run the nodeJS container by forwarding its port 80 the host: 1. Try to reach the port 80 2. Inspect the current ndoeJS container 3. Remove the nodeJS container 4. Run the nodeJS container test.js file, mapping the port 80 5. Inspect the nodeJS container
  • 10. Port publishing docker inspect nodejs curl <IP> docker ps docker images docker rm -f nodejs docker run -d -p 80:80 --name nodejs tribalnova/nodejs node /var/www/tuto/test.js docker logs nodejs docker inspect nodejs curl <IP>
  • 11. Volume share Run the nodeJS container by sharing its project volume: 1. Remove the previous nodejs container 2. Run it again by sharing /var/www/tuto with the host 3. Try to reach its port 80 4. Remove the nodeJS container 5. Launch it by mapping the port 80 6. Retry to reach its port 80
  • 12. Volume share docker rm -f nodejs vi /var/www/tuto/test.js docker run -d -p 80:80 -v /var/www/tuto:/var/www/tuto --name nodejs tribalnova/nodejs node /var/www/tuto/test.js docker logs nodejs docker inspect nodejs curl <IP>
  • 13. Environment variable Run the nodeJS container and pass an environment variable: 1. Remove the previous nodejs container 2. Run it again by passing a variable TEST=TUTO to it 3. Inspect the container 4. Connect to it 5. Display the environment variable 6. Remove the container
  • 14. Environment variable docker rm -f nodejs docker run -d -p 80:80 -e TEST=TUTO -v /var/www/tuto:/var/www/tuto -- name nodejs tribalnova/nodejs node /var/www/tuto/test.js docker inspect nodejs docker exec -ti nodejs zsh #env #exit docker rm -f nodejs
  • 15. Dockerfile Run the nodeJS container from Dockerfile images Documentation : https://docs.docker.com/reference/builder/ 1. Create a Dockerfile image with only a nodeJS server installed, in the directory docker/nodejs 2. Build it, and name the image tribalnova/nodejs 3. Create a Dockerfile image that inherits from the image tribalnova/nodejs, that embeds the test.js file, and launch it through nodeJS as a default command, in the directory docker/tuto 4. Build it and name the image tribalnova/tuto 5. Run in a container the image tribalnova/tuto, by sharing the volume and publishing the port as before 6. Test it
  • 16. Dockerfile cd docker mkdir nodejs cd nodejs vi Dockerfile docker build -t tribalnova/nodejs . cd .. mkdir tuto cd tuto vi test.js vi Dockerfile docker build -t tribalnova/tuto . docker run --rm -ti -p 80:80 tribalnova/tuto docker run --name nodejs -d -v /var/www/tuto:/var/www/tuto -p 80:80 tribalnova/tuto vi /var/www/tuto/test.js <change the hello world message> docker stop nodejs docker start nodejs FROM tribalnova/baseimage-ubuntu1404 MAINTAINER me RUN apt-get update && apt-get install -y nodejs- legacy npm RUN /var/docker/install-devtools.sh && rm /var/docker/install-devtools.sh nodejs/Dockerfile FROM tribalnova/nodejs MAINTAINER me ADD test.js /var/www/tuto/test.js WORKDIR /var/www/tuto EXPOSE 80 CMD node /var/www/tuto/test.js tuto/Dockerfile
  • 17. Docker push Push the docker images to Dockerhub 1. Login 2. Push tribalnova/nodejs 3. Push tribalnova/tuto 4. Logout
  • 18. Docker push docker login docker push tribalnova/nodejs docker search nodejs docker logout docker search nodejs
  • 19. Container linking Launch a mongoDB container and create a nodeJS container with an application that connects to it 1. Find and launch the mongoDB official container 2. Run the container tribalnova/tuto in daemon, by linking the mongo container to it 3. Inspect the container 4. Execute a zsh command on it 1. Display the environment variables 2. Test the mongoDB connection 3. Install the nodeJS mongodb package with npm 4. Create the test2.js file (provided file) 5. Commit this container image as tribalnova/tuto2 6. Run it on the port 81 in rm mode, launching test2.js through nodeJS
  • 20. Container linking var http = require("http"); var MongoClient = require('mongodb').MongoClient var url = 'mongodb://mongo:27017/tuto'; http.createServer(function (request, response) { response.writeHead(200, { 'Content-Type': 'text/plain' }); MongoClient.connect(url, function(err, db) { if(err) throw err; var collection = db.collection('samples'); collection.insert([ {'hello' : 'world'}, {'et' : 'cetera'}, {'et' : {'cetera':'et cetera'}} ], {w:1}, function(err, result) { collection.find().toArray(function(err, docs) { response.end(JSON.stringify(docs)); }); }); }); }).listen(80); console.log("Server running"); test2.js
  • 21. Container linking docker search mongo docker run -d --name mongo mongo docker run --name nodejs --link mongo:mongo -d -p 80:80 tribalnova/tuto docker inspect nodejs docker exec -ti nodejs zsh #env #more /etc/hosts #nc -zv mongo 27017 #cd /var/www/tuto #npm install mongodb #vi test2.js #exit docker commit nodejs tribalnova/tuto2 docker run --rm --link mongo:mongo -p 81:80 tribalnova/tuto2 node test2.js
  • 22. Linked container Dockerfile Create a Dockerfile for a container that embeds the two nodeJS projects 1. Create a docker/tuto2 directory 2. Put the project files inside 3. Create a Dockerfile with: 1. An entrypoint that launch the node executable 2. The container must launch test.js by default 4. Build the image, naming it tribalnova/tuto2 5. Run a container with the default command, with the rm option 6. Run a container with node executing test2.js, with the rm option
  • 23. Linked container Dockerfile cd docker mkdir tuto2 <copy files test.js and test2.js inside> vi Dockerfile docker build -t tribalnova/tuto2 . docker run --rm --link mongo:mongo –p 80:80 tribalnova/tuto2 <CTRL+C> docker run --rm --link mongo:mongo –p 80:80 tribalnova/tuto2 test2.js FROM tribalnova/nodejs MAINTAINER me RUN npm install mongodb ADD test.js /var/www/tuto/test.js ADD test2.js /var/www/tuto/test2.js WORKDIR /var/www/tuto EXPOSE 80 ENTRYPOINT ["node"] CMD ["test.js"] tuto2/Dockerfile
  • 24. Vagrant provisioner Modify the Vagrant file to build and launch the containers upon provisioning. Documentation: http://docs.vagrantup.com/v2/provisioning/docker.html 1. Clear the containers and images 2. Alter Vagrantfile 3. Run the provising
  • 25. Vagrant provisioner docker ps -qa | xargs docker rm -f docker images -q | xargs docker rmi –f ON THE HOST MACHINE: <insert the Vagrantfile docker section> vagrant provision config.vm.provision "docker" do |d| d.run "mongo", daemonize: true, args: "--name mongo" d.build_image "./docker/nodejs", args: "-t tribalnova/nodejs" d.build_image "./docker/tuto", args: "-t tribalnova/tuto" d.build_image "./docker/tuto2", args: "-t tribalnova/tuto2" d.run "tribalnova/tuto", daemonize: true, args: "--name tuto --link mongo:mongo -p 80:80" d.run "tribalnova/tuto2", daemonize: true, args: "--name tuto2 --link mongo:mongo -p 81:80" end Vagrantfile