3. What is a container?
• Program executed in a limited kernel resources
• Cgroups: CPU, Memory, Network, …
• Namespace: Process, User, Filesystem, ...
• Union file system: Filesystem
4. Virtual machine vs Container
Server
OS
Hypervisor
Guest OS
Libraries
App 1
Server
OS
Docker Engine
Guest OS Guest OS
Libraries Libraries
App 2 App 3
Libraries
App 1
Libraries Libraries
App 2 App 3
5. Containers for developers
• Micro service paradigm
• Environment variables for application configuration
User
Contract
Support
Notification
Analytics
Invoice
Storage
Task
6. Containers for system engineers
• Blue/Green deployment
• High level management
• Security issues
• Change all tools…
User
Load balancer
A version
B version
A version
B version
A version
B version
Web server Application Database
10. Dockerfile
• Dockerfile is a document composed of various commands to assemble
an image
• Inherit from on a base image
11. Dockerfile
FROM ubuntu
MAINTAINER SvenDowideit@docker.com
RUN apt-key adv --keyserverhkp://p80.pool.sks-keyservers.net:80--recv-keys
B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdgmain">/etc/apt/sources.list.d/pgdg.list
RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3
postgresql-contrib-9.3
USER postgres
RUN /etc/init.d/postgresqlstart &&
psql --command "CREATE USER dockerWITH SUPERUSER PASSWORD 'docker';"&&
createdb -O dockerdocker
RUN echo "host all all 0.0.0.0/0 md5">> /etc/postgresql/9.3/main/pg_hba.conf
RUN echo "listen_addresses='*'">> /etc/postgresql/9.3/main/postgresql.conf
EXPOSE 5432
VOLUME ["/etc/postgresql","/var/log/postgresql","/var/lib/postgresql"]
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
Base image
Maintainer information
Install requirements
Set user to use when
running the image
Application configuration
Export port on network
Export volumes
Start application
12. Docker compose
• Compose is a tool for defining and running multi-container Docker
applications
• /! 2 versions of docker-compose format
18. Create your first container
• Start Docker server
docker-machine start default
• Load Docker connection parameters
eval $(docker-machine env default)
• Create Dockerfile
FROM php
WORKDIR /var/www
ADD index.php .
EXPOSE 8080
ENTRYPOINT ["php", "-S", "0.0.0.0:8080"]
19. Start your first container
• Create index.php
echo '<?php echo ”Good morning!n”; ?>' > index.php
• Build container
docker build -t app1 .
• Check images
docker images | head
• Run the container
docker run -t app1 -p 8080:8080 app1
• Connect to the website
curl -v $(docker-machine ip):8080
20. Update the container
• Update application content
echo '<?php echo "Welcome!n”;?>' > index.php
• Connect to the website
curl -v $(docker-machine ip):8080
• Still Good morning… What’s wrong?
• Restart your container
21. Share your container
• Create an account on https://hub.docker.com
• Tag your container
docker tag app1 <username>/app1
• Connect on Dockerhub
docker login
• Push container to Docker Hub
docker push <username>/app1
• Connect on DockerHub website
https://hub.docker.com/<username>/app1/
22. cAdvisor
• Created by Google to monitor their own containers (lmctfy)
• Analyzes resource usage and performance characteristics of running
containers.
23. Start cAdvisor
• Run cAdvisor
docker run
--name=cadvisor
--restart always
--detach=true
--volume=/:/rootfs:ro
--volume=/var/run:/var/run:rw
--volume=/sys:/sys:ro
--volume=/var/lib/docker/:/var/lib/docker:ro
--publish=8001:8080
google/cadvisor:latest
• Connect to the web interface
http://192.168.99.100:8001
25. Continuous integration/deployment
• Continuous integration
• Run tests for each commit
• Detect bugs
• Continuous deployment
• Deploy application if tests success
GIT repository
CI CD
ProductionStaging
Developer
26. Gitlab
• Open source GIT repository management solution
• Community and Enterprise editions
• GitHub alternative
• https://about.gitlab.com
27. Start GitLab
• Run GitLab
docker run --detach
--hostname gitlab.example.com
--publish8000:80
--name gitlab
--restart always
--volume /srv/gitlab/config:/etc/gitlab
--volume /srv/gitlab/logs:/var/log/gitlab
--volume /srv/gitlab/data:/var/opt/gitlab
gitlab/gitlab-ce:latest
• Connect to the web interface(Default password: root/5iveL!fe)
http://$(docker-machine ip):8000
30. Jenkins
• The most popular tool to build and deploy projects
• Unittest
• Continuous Integration
• Continuous Delivery
• Plugins for everything!
• Distribute work across multiple machines
• https://jenkins.io
31. Start Jenkins
• Run Jenkins
docker run --detach
--publish 10000:8080
--name jenkins
--restart always
jenkins:latest
• Connect to the web interface
http://$(docker-machine ip):10000