Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Docker in Action
Alper Kanat <alper.kanat@commencis.com>
Let’s go back in time a bit...
Please take a look at the previous keynote to have a brief introduction to Docker!
https://www.slideshare.net/AlperKanat/next-in-virtualization-era-containerization-docker
After Virtualbox & homebrew installation...
$ brew install docker
$ brew install docker-machine
$ docker-machine create -d virtualbox --virtualbox-memory "2048" default
Image cache does not exist, creating it at /Users/kanata/.docker/machine/cache...
No default boot2docker iso found locally, downloading the latest release...
Downloading https://github.com/boot2docker/boot2docker/releases/download/v1.8.3/boot2docker.iso to
/Users/kanata/.docker/machine/cache/boot2docker.iso...
Creating VirtualBox VM...
Creating SSH key...
Starting VirtualBox VM...
Starting VM...
To see how to connect Docker to this machine, run: docker-machine env default
$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/kanata/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval "$(docker-machine env default)"
$ eval "$(docker-machine env default)"
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
boot2docker
$ docker run --name tunix -it --rm ubuntu /bin/echo 'Hello World!'
Hello World!
$
Checkout docker manual (docker run --help) or its website for other arguments.
Hello World
Assigns the given name to
container for later use
Makes container session interactive for
testing or preperation
Deletes container when the
working process quits
Container image to use.
Usually suffixed by version
(e.g.: ubuntu:16.04)
The command that the process will be
executed by. This is usually omitted for
production containers.
The output of the running
process.
Dockerfile
FROM ubuntu:16.04
MAINTAINER Alper Kanat <alper.kanat@commencis.com>
RUN sed -i "s/archive.ubuntu/tr.archive.ubuntu/g" /etc/apt/sources.list
RUN apt-get -qq update
RUN apt-get -qqy upgrade
RUN apt-get install -qqy nodejs nodejs-legacy npm git
RUN npm install -g bower gulp
ADD . /srv
WORKDIR /srv
RUN npm install
RUN bower install --allow-root
RUN gulp clean build
ENV NODE_ENV production
EXPOSE 3000
CMD ["./app.js"]
Dockerfile (cont’d)
Notes about Dockerfile
● Dockerfile is usually placed inside the root folder of the project
● Multiple Dockerfile’s can be placed within a project
● Dockerfile is being used for generating base/container images
● Each statement in Dockerfile are committed in order, hence yield new layers of the resulting
image.
● Image layers are reusable so we should try our best to prevent changes to Dockerfile and add new
statements to the bottom of Dockerfile whenever possible. If a layer changes, all layers after
that one will be regenerated, causing an even larger image.
● Usually a base image is being used for each new image. A “Hello World Spring Boot” app can be
based on top of a Java image. However a base Ubuntu image can be used to start from scratch.
● You should have a clear understanding of network ports & volume usage before writing a new
Dockerfile.
● Consider reading the reference manual to learn more about writing Dockerfile’s.
Spring Boot
Hello World App
Demo 1
In our sandbox environment, we have “s1” (sandbox-1) & “s2” (sandbox-2) configured as Docker servers. We use
them to deploy & run your containers to the sandbox environment just like we do for any app. The remote docker
server is determined via environment variables.
$ export DOCKER_HOST=tcp://s1.sandbox.company.com:2375
$ export DOCKER_TLS_VERIFY=
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8248fe49b1d2 tunix/tomcat:8.0 "/run.sh" 5 weeks ago Up 5 weeks 0.0.0.0:8081->8080/tcp tomcat8
b25a77110d2c tunix/tomcat-java8:8.0 "/run.sh" 5 weeks ago Up 5 weeks 0.0.0.0:8082->8080/tcp tomcat8-j8
7ad53d9921bf tunix/tomcat:7.0 "/run.sh" 5 weeks ago Up 2 days 0.0.0.0:8080->8080/tcp tomcat7
There are 2 ways to deploy containers to remote docker servers. Either build container image on the server itself or copy the image onto
the server:
$ docker save -o ~/Desktop/my-image-name.tar my-image-name
$ scp ~/Desktop/my-image-name.tar s1.sandbox.company.com:
$ ssh s1.sandbox.company.com
$ docker load -i ~/my-image-name.tar
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tunix/tomcat-java8 8.0 ac81155e8a00 5 weeks ago 573.2 MB
tunix/tomcat 7.0 1ab892df6239 5 weeks ago 863.1 MB
tunix/tomcat 8.0 25fd96065ad8 5 weeks ago 539.4 MB
Deployment (sandbox)
Docker Hub
$ docker search mongodb
$ docker pull ubuntu:16.04
$ docker login
$ docker push tunix/tomcat-java8:8.0
● So we can create custom container images, deploy and reuse
● Supports auto builds from github & bitbucket
Docker Services (tutum)
● A commit to your github ends up as a container in your services: Poor Man’s AWS!
● Compose your architecture with stack files for auto creation & management of containers
● Auto scaling (even with labels) allows you to span over single/multiple machines
Questions?
(Thank you!)

More Related Content

Docker in Action

  • 1. Docker in Action Alper Kanat <alper.kanat@commencis.com>
  • 2. Let’s go back in time a bit... Please take a look at the previous keynote to have a brief introduction to Docker! https://www.slideshare.net/AlperKanat/next-in-virtualization-era-containerization-docker
  • 3. After Virtualbox & homebrew installation... $ brew install docker $ brew install docker-machine $ docker-machine create -d virtualbox --virtualbox-memory "2048" default Image cache does not exist, creating it at /Users/kanata/.docker/machine/cache... No default boot2docker iso found locally, downloading the latest release... Downloading https://github.com/boot2docker/boot2docker/releases/download/v1.8.3/boot2docker.iso to /Users/kanata/.docker/machine/cache/boot2docker.iso... Creating VirtualBox VM... Creating SSH key... Starting VirtualBox VM... Starting VM... To see how to connect Docker to this machine, run: docker-machine env default $ docker-machine env default export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/kanata/.docker/machine/machines/default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval "$(docker-machine env default)" $ eval "$(docker-machine env default)" $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES boot2docker
  • 4. $ docker run --name tunix -it --rm ubuntu /bin/echo 'Hello World!' Hello World! $ Checkout docker manual (docker run --help) or its website for other arguments. Hello World Assigns the given name to container for later use Makes container session interactive for testing or preperation Deletes container when the working process quits Container image to use. Usually suffixed by version (e.g.: ubuntu:16.04) The command that the process will be executed by. This is usually omitted for production containers. The output of the running process.
  • 5. Dockerfile FROM ubuntu:16.04 MAINTAINER Alper Kanat <alper.kanat@commencis.com> RUN sed -i "s/archive.ubuntu/tr.archive.ubuntu/g" /etc/apt/sources.list RUN apt-get -qq update RUN apt-get -qqy upgrade RUN apt-get install -qqy nodejs nodejs-legacy npm git RUN npm install -g bower gulp ADD . /srv WORKDIR /srv RUN npm install RUN bower install --allow-root RUN gulp clean build ENV NODE_ENV production EXPOSE 3000 CMD ["./app.js"]
  • 6. Dockerfile (cont’d) Notes about Dockerfile ● Dockerfile is usually placed inside the root folder of the project ● Multiple Dockerfile’s can be placed within a project ● Dockerfile is being used for generating base/container images ● Each statement in Dockerfile are committed in order, hence yield new layers of the resulting image. ● Image layers are reusable so we should try our best to prevent changes to Dockerfile and add new statements to the bottom of Dockerfile whenever possible. If a layer changes, all layers after that one will be regenerated, causing an even larger image. ● Usually a base image is being used for each new image. A “Hello World Spring Boot” app can be based on top of a Java image. However a base Ubuntu image can be used to start from scratch. ● You should have a clear understanding of network ports & volume usage before writing a new Dockerfile. ● Consider reading the reference manual to learn more about writing Dockerfile’s.
  • 8. In our sandbox environment, we have “s1” (sandbox-1) & “s2” (sandbox-2) configured as Docker servers. We use them to deploy & run your containers to the sandbox environment just like we do for any app. The remote docker server is determined via environment variables. $ export DOCKER_HOST=tcp://s1.sandbox.company.com:2375 $ export DOCKER_TLS_VERIFY= $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8248fe49b1d2 tunix/tomcat:8.0 "/run.sh" 5 weeks ago Up 5 weeks 0.0.0.0:8081->8080/tcp tomcat8 b25a77110d2c tunix/tomcat-java8:8.0 "/run.sh" 5 weeks ago Up 5 weeks 0.0.0.0:8082->8080/tcp tomcat8-j8 7ad53d9921bf tunix/tomcat:7.0 "/run.sh" 5 weeks ago Up 2 days 0.0.0.0:8080->8080/tcp tomcat7 There are 2 ways to deploy containers to remote docker servers. Either build container image on the server itself or copy the image onto the server: $ docker save -o ~/Desktop/my-image-name.tar my-image-name $ scp ~/Desktop/my-image-name.tar s1.sandbox.company.com: $ ssh s1.sandbox.company.com $ docker load -i ~/my-image-name.tar $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE tunix/tomcat-java8 8.0 ac81155e8a00 5 weeks ago 573.2 MB tunix/tomcat 7.0 1ab892df6239 5 weeks ago 863.1 MB tunix/tomcat 8.0 25fd96065ad8 5 weeks ago 539.4 MB Deployment (sandbox)
  • 9. Docker Hub $ docker search mongodb $ docker pull ubuntu:16.04 $ docker login $ docker push tunix/tomcat-java8:8.0 ● So we can create custom container images, deploy and reuse ● Supports auto builds from github & bitbucket
  • 10. Docker Services (tutum) ● A commit to your github ends up as a container in your services: Poor Man’s AWS! ● Compose your architecture with stack files for auto creation & management of containers ● Auto scaling (even with labels) allows you to span over single/multiple machines