Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Docker for Developers

Docker for Developers

How to use docker/containers for day to day software development, without changing your original workflow. Build, run and debug iyour application in docker

Kunal Kushwaha

July 04, 2017
Tweet

More Decks by Kunal Kushwaha

Other Decks in Technology

Transcript

  1. Agenda Containers basics. Docker cli. Building and compiling your application

    in docker containers. Running applications in containers. Debugging application in containers. Distributing your application as docker images.
  2. 10 mins Introduction to containers 20 mins Docker cli 30

    mins Building and compiling your application 30 mins Running and debugging application in container 30 mins Distributing your application as container
  3. Docker for Developers - Do we gonna learn new workflow?

    - No, Docker adapts to your workflow. You will continue to develop, build, test , ship with same workflow.
  4. Docker for Developers - Do we gonna learn new workflow?

    - No, Docker adapts to your workflow. You will continue to develop, build, test , ship with same workflow. - Any preferred programming language to use docker?
  5. Docker for Developers - Do we gonna learn new workflow?

    - No, Docker adapts to your workflow. You will continue to develop, build, test , ship with same workflow. - Any preferred programming language to use docker? - Docker is language agnostic tool. You can use any language and variety of platforms including Windows, Linux, Mac.
  6. Docker for Developers - Do we gonna learn new workflow?

    - No, Docker adapts to your workflow. You will continue to develop, build, test , ship with same workflow. - Which IDE you suggest to develop with Docker? - Any preferred programming language to use docker? - Docker is language agnostic tool. You can use any language and variety of platforms including Windows, Linux, Mac.
  7. Docker for Developers - Do we gonna learn new workflow?

    - No, Docker adapts to your workflow. You will continue to develop, build, test , ship with same workflow. - Which IDE you suggest to develop with Docker? - There are few IDE’s integrated with Docker like Code, NetBeans, Eclipse , IntelliJ etc. - But today, we will not be using any IDE., instead we will use command line tool. - Any preferred programming language to use docker? - Docker is language agnostic tool. You can use any language and variety of platforms including Windows, Linux, Mac.
  8. Docker Docker is container platform, which provides all tooling for

    end to end solutions for software development, distribution, deployment & management. “Build, Ship, Run anywhere”
  9. Containers An entity in linux system, which provides isolation and

    control of resources to process(s) Docker Docker is container platform, which provides all tooling for end to end solutions for software development, distribution, deployment & management. “Build, Ship, Run anywhere”
  10. Containers An entity in linux system, which provides isolation and

    control of resources to process(s) - Cgroups - Namespaces Docker Docker is container platform, which provides all tooling for end to end solutions for software development, distribution, deployment & management. “Build, Ship, Run anywhere”
  11. Containers An entity in linux system, which provides isolation and

    control of resources to process(s) - Cgroups - Namespaces + SELinux + seccomp Docker Docker is container platform, which provides all tooling for end to end solutions for software development, distribution, deployment & management. “Build, Ship, Run anywhere”
  12. Containers An entity in linux system, which provides isolation and

    control of resources to process(s) - Cgroups - Namespaces + SELinux + seccomp Docker Docker is container platform, which provides all tooling for end to end solutions for software development, distribution, deployment & management. “Build, Ship, Run anywhere” Docker Containers Docker container packs everything required to make a piece of software run in isolation. Apps have Sandboxed environment, with their own dependencies installed without conflict
  13. Docker Image vs Docker Container Docker Image: - Image is

    an inert & immutable file which is used as template to create Docker Container. - You can think of ELF (.exe/ executable) Docker Container: - Running instance of docker image is docker container. - Think of running process
  14. Docker CLI $ docker Our Target - Most of subcommands

    under “container” & “image” are available as docker <command> too!
  15. Docker CLI $ docker run -it alpine sh Interactive &

    Assign a terminal Start container with this command( PID 1)
  16. Docker CLI $ docker run -it alpine sh Interactive &

    Assign a terminal Start container with this command( PID 1)
  17. Docker CLI $ docker run -it alpine sh Interactive &

    Assign a terminal Start container with this command( PID 1)
  18. Docker CLI $ docker run -it alpine sh Interactive &

    Assign a terminal Start container with this command( PID 1)
  19. Docker CLI $ docker run -it alpine sh Interactive &

    Assign a terminal Start container with this command( PID 1)
  20. Docker CLI $ docker run -it alpine sh Interactive &

    Assign a terminal Start container with this command( PID 1)
  21. Docker Cli $docker ps $docker ps -a Unique ID 64

    hex string Image Starting command
  22. Docker Cli $docker ps $docker ps -a Unique ID 64

    hex string Image Starting command
  23. Docker Cli $docker ps $docker ps -a Unique ID 64

    hex string Image Starting command
  24. Docker Cli $docker ps $docker ps -a Unique ID 64

    hex string Image Starting command Names automatically assigned if not provided
  25. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal $docker exec <flags> [container-name| id] <command>
  26. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal $docker exec <flags> [container-name| id] <command>
  27. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal $docker exec <flags> [container-name| id] <command>
  28. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal Executes command in container $docker exec <flags> [container-name| id] <command>
  29. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal Executes command in container $docker exec <flags> [container-name| id] <command>
  30. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal Executes command in container $docker exec <flags> [container-name| id] <command>
  31. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal Executes command in container $docker exec <flags> [container-name| id] <command>
  32. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal Executes command in container $docker exec <flags> [container-name| id] <command>
  33. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal Executes command in container $docker exec <flags> [container-name| id] <command>
  34. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal Executes command in container $docker exec <flags> [container-name| id] <command>
  35. Docker Cli $docker exec -it test sh Interactive & Assign

    a terminal Executes command in container $docker exec <flags> [container-name| id] <command>
  36. Docker CLI $ docker logs <container-id | container name> -

    Prints output of container. - Could be used to see output of container running in background or exited containers. $ docker stats - Shows the resource utilization of all running containers. $ docker rm <container -id | name> - Deletes the container (works on non-running containers only) $ docker rmi <image id | name> - Deletes the image (If image have no reference)
  37. Dockerfile. - A text document that contains all the commands

    a user could call on the command line to assemble an image.
  38. Dockerfile. - A text document that contains all the commands

    a user could call on the command line to assemble an image. # Comment INSTRUCTION arguments Format
  39. Dockerfile. - A text document that contains all the commands

    a user could call on the command line to assemble an image. # Comment INSTRUCTION arguments Format - “docker build” executes commands from Dockerfile in succession to build an image.
  40. Dockerfile. - A text document that contains all the commands

    a user could call on the command line to assemble an image. # Comment INSTRUCTION arguments Format FROM alpine:latest RUN echo "Hello World" > /tmp/hello.txt CMD cat /tmp/hello.txt - “docker build” executes commands from Dockerfile in succession to build an image.
  41. Dockerfile. - A text document that contains all the commands

    a user could call on the command line to assemble an image. # Comment INSTRUCTION arguments Format $ docker build -t kk/hello . Sending build context to Docker daemon 2.048 kB Step 1/3 : FROM alpine:latest ---> 665ffb03bfae Step 2/3 : RUN echo "Hello World" > /tmp/hello.txt ---> Running in 22b418c7f275 ---> 7c7e9d46af10 Removing intermediate container 22b418c7f275 Step 3/3 : CMD cat /tmp/hello.txt ---> Running in 666e4c0e8796 ---> 0aa564c19761 Removing intermediate container 666e4c0e8796 Successfully built 0aa564c19761 FROM alpine:latest RUN echo "Hello World" > /tmp/hello.txt CMD cat /tmp/hello.txt - “docker build” executes commands from Dockerfile in succession to build an image.
  42. Dockerfile. - A text document that contains all the commands

    a user could call on the command line to assemble an image. # Comment INSTRUCTION arguments Format $ docker build -t kk/hello . Sending build context to Docker daemon 2.048 kB Step 1/3 : FROM alpine:latest ---> 665ffb03bfae Step 2/3 : RUN echo "Hello World" > /tmp/hello.txt ---> Running in 22b418c7f275 ---> 7c7e9d46af10 Removing intermediate container 22b418c7f275 Step 3/3 : CMD cat /tmp/hello.txt ---> Running in 666e4c0e8796 ---> 0aa564c19761 Removing intermediate container 666e4c0e8796 Successfully built 0aa564c19761 FROM alpine:latest RUN echo "Hello World" > /tmp/hello.txt CMD cat /tmp/hello.txt - “docker build” executes commands from Dockerfile in succession to build an image.
  43. Dockerfile. - A text document that contains all the commands

    a user could call on the command line to assemble an image. # Comment INSTRUCTION arguments Format $ docker build -t kk/hello . Sending build context to Docker daemon 2.048 kB Step 1/3 : FROM alpine:latest ---> 665ffb03bfae Step 2/3 : RUN echo "Hello World" > /tmp/hello.txt ---> Running in 22b418c7f275 ---> 7c7e9d46af10 Removing intermediate container 22b418c7f275 Step 3/3 : CMD cat /tmp/hello.txt ---> Running in 666e4c0e8796 ---> 0aa564c19761 Removing intermediate container 666e4c0e8796 Successfully built 0aa564c19761 FROM alpine:latest RUN echo "Hello World" > /tmp/hello.txt CMD cat /tmp/hello.txt - “docker build” executes commands from Dockerfile in succession to build an image.
  44. Dockerfile. - A text document that contains all the commands

    a user could call on the command line to assemble an image. # Comment INSTRUCTION arguments Format $ docker build -t kk/hello . Sending build context to Docker daemon 2.048 kB Step 1/3 : FROM alpine:latest ---> 665ffb03bfae Step 2/3 : RUN echo "Hello World" > /tmp/hello.txt ---> Running in 22b418c7f275 ---> 7c7e9d46af10 Removing intermediate container 22b418c7f275 Step 3/3 : CMD cat /tmp/hello.txt ---> Running in 666e4c0e8796 ---> 0aa564c19761 Removing intermediate container 666e4c0e8796 Successfully built 0aa564c19761 FROM alpine:latest RUN echo "Hello World" > /tmp/hello.txt CMD cat /tmp/hello.txt - “docker build” executes commands from Dockerfile in succession to build an image.
  45. Dockerfile. - A text document that contains all the commands

    a user could call on the command line to assemble an image. # Comment INSTRUCTION arguments Format $ docker build -t kk/hello . Sending build context to Docker daemon 2.048 kB Step 1/3 : FROM alpine:latest ---> 665ffb03bfae Step 2/3 : RUN echo "Hello World" > /tmp/hello.txt ---> Running in 22b418c7f275 ---> 7c7e9d46af10 Removing intermediate container 22b418c7f275 Step 3/3 : CMD cat /tmp/hello.txt ---> Running in 666e4c0e8796 ---> 0aa564c19761 Removing intermediate container 666e4c0e8796 Successfully built 0aa564c19761 FROM alpine:latest RUN echo "Hello World" > /tmp/hello.txt CMD cat /tmp/hello.txt - “docker build” executes commands from Dockerfile in succession to build an image.
  46. Dockerfile Instructions FROM [image]:<tag> - The FROM instruction sets the

    Base Image for subsequent instructions - must be the first non-comment instruction in the Dockerfile. - Tag is optional, If you omit, the builder assumes a latest by default.
  47. Dockerfile Instructions FROM [image]:<tag> - The FROM instruction sets the

    Base Image for subsequent instructions - must be the first non-comment instruction in the Dockerfile. - Tag is optional, If you omit, the builder assumes a latest by default. FROM alpine:latest example
  48. Dockerfile Instructions FROM [image]:<tag> - The FROM instruction sets the

    Base Image for subsequent instructions - must be the first non-comment instruction in the Dockerfile. - Tag is optional, If you omit, the builder assumes a latest by default. FROM alpine:latest example
  49. Dockerfile Instructions FROM [image]:<tag> - The FROM instruction sets the

    Base Image for subsequent instructions - must be the first non-comment instruction in the Dockerfile. - Tag is optional, If you omit, the builder assumes a latest by default. FROM alpine:latest example https://hub.docker.com/explore/
  50. Dockerfile Instructions RUN <command> or RUN ["executable", "param1",...] - Execute

    any commands in a new layer on top of the current image and commit the results. - The resulting committed image will be used for the next step in the Dockerfile.
  51. Dockerfile Instructions RUN <command> or RUN ["executable", "param1",...] - Execute

    any commands in a new layer on top of the current image and commit the results. - The resulting committed image will be used for the next step in the Dockerfile. FROM ubuntu RUN [“apt-get”, “install”, “httpd”] RUN echo “hello-world” >> /tmp/hello.txt CMD cat /tmp/hello.txt example
  52. Dockerfile Instructions RUN <command> or RUN ["executable", "param1",...] - Execute

    any commands in a new layer on top of the current image and commit the results. - The resulting committed image will be used for the next step in the Dockerfile. FROM ubuntu RUN [“apt-get”, “install”, “httpd”] RUN echo “hello-world” >> /tmp/hello.txt CMD cat /tmp/hello.txt example CMD <command> or RUN ["executable", "param1",...] - CMD provides defaults for an executing container. - Executable or arguments ENTRYPOINT - There can only be one CMD instruction in a Dockerfile
  53. Dockerfile Instructions RUN <command> or RUN ["executable", "param1",...] - Execute

    any commands in a new layer on top of the current image and commit the results. - The resulting committed image will be used for the next step in the Dockerfile. FROM ubuntu RUN [“apt-get”, “install”, “httpd”] RUN echo “hello-world” >> /tmp/hello.txt CMD cat /tmp/hello.txt example CMD <command> or RUN ["executable", "param1",...] - CMD provides defaults for an executing container. - Executable or arguments ENTRYPOINT - There can only be one CMD instruction in a Dockerfile $ docker run kk/hello Hello World
  54. Dockerfile Instructions ENV <key> <value> ENV <key>=<value> ... - Sets

    the environment variable <key> to the value <value>
  55. Dockerfile Instructions ENV <key> <value> ENV <key>=<value> ... - Sets

    the environment variable <key> to the value <value> FROM ubuntu ENV http_proxy=”example.com/8080” RUN [“apt-get”, “install”, “httpd”] ADD http://example.com/foobar / example
  56. Dockerfile Instructions ENV <key> <value> ENV <key>=<value> ... - Sets

    the environment variable <key> to the value <value> FROM ubuntu ENV http_proxy=”example.com/8080” RUN [“apt-get”, “install”, “httpd”] ADD http://example.com/foobar / example ADD <src>... <dest> or ADD [“<src>”,.. “<dest>”] - Copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the image at the path <dest>. - Multiple <src> must be from relative to build context. - If <src> is in recognized compression format, it will be unpacked.
  57. Dockerfile Instructions COPY <src>... <dest> or ADD [“<src>”,.. “<dest>”] -

    Same as ADD, without URL support. ENTRYPOINT ["executable", "param1", "param2"] ENTRYPOINT command param1 param2 - Allows to configure a container that will run as an executable (PID 1). - Command and Arguments cannot be overridden. - CMD is used to pass default arguments, that can be overridden from CLI.
  58. Dockerfile Instructions COPY <src>... <dest> or ADD [“<src>”,.. “<dest>”] -

    Same as ADD, without URL support. FROM ubuntu ENTRYPOINT ["top", "-b"] CMD ["-c"] example ENTRYPOINT ["executable", "param1", "param2"] ENTRYPOINT command param1 param2 - Allows to configure a container that will run as an executable (PID 1). - Command and Arguments cannot be overridden. - CMD is used to pass default arguments, that can be overridden from CLI.
  59. Dockerfile Instructions VOLUME [“<mount-point>”...] or VOLUME <mount-point> - Creates a

    mount point with the specified name - Marks it as holding externally mounted volumes from native host or other containers - If any build steps change the data within the volume after it has been declared, those changes will be discarded. - Host directory cannot be specified in Dockerfile.
  60. Dockerfile Instructions VOLUME [“<mount-point>”...] or VOLUME <mount-point> - Creates a

    mount point with the specified name - Marks it as holding externally mounted volumes from native host or other containers - If any build steps change the data within the volume after it has been declared, those changes will be discarded. - Host directory cannot be specified in Dockerfile. FROM ubuntu RUN mkdir /myvol RUN echo "hello world" > /myvol/greeting VOLUME /myvol example
  61. Dockerfile Instructions VOLUME [“<mount-point>”...] or VOLUME <mount-point> - Creates a

    mount point with the specified name - Marks it as holding externally mounted volumes from native host or other containers - If any build steps change the data within the volume after it has been declared, those changes will be discarded. - Host directory cannot be specified in Dockerfile. FROM ubuntu RUN mkdir /myvol RUN echo "hello world" > /myvol/greeting VOLUME /myvol example
  62. Dockerfile Instructions VOLUME [“<mount-point>”...] or VOLUME <mount-point> - Creates a

    mount point with the specified name - Marks it as holding externally mounted volumes from native host or other containers - If any build steps change the data within the volume after it has been declared, those changes will be discarded. - Host directory cannot be specified in Dockerfile. FROM ubuntu RUN mkdir /myvol RUN echo "hello world" > /myvol/greeting VOLUME /myvol example 1
  63. Dockerfile Instructions VOLUME [“<mount-point>”...] or VOLUME <mount-point> - Creates a

    mount point with the specified name - Marks it as holding externally mounted volumes from native host or other containers - If any build steps change the data within the volume after it has been declared, those changes will be discarded. - Host directory cannot be specified in Dockerfile. FROM ubuntu RUN mkdir /myvol RUN echo "hello world" > /myvol/greeting VOLUME /myvol example 1 2
  64. Dockerfile Instructions VOLUME [“<mount-point>”...] or VOLUME <mount-point> - Creates a

    mount point with the specified name - Marks it as holding externally mounted volumes from native host or other containers - If any build steps change the data within the volume after it has been declared, those changes will be discarded. - Host directory cannot be specified in Dockerfile. FROM ubuntu RUN mkdir /myvol RUN echo "hello world" > /myvol/greeting VOLUME /myvol example 1 2
  65. Dockerfile Instructions VOLUME [“<mount-point>”...] or VOLUME <mount-point> - Creates a

    mount point with the specified name - Marks it as holding externally mounted volumes from native host or other containers - If any build steps change the data within the volume after it has been declared, those changes will be discarded. - Host directory cannot be specified in Dockerfile. FROM ubuntu RUN mkdir /myvol RUN echo "hello world" > /myvol/greeting VOLUME /myvol example 1 2
  66. Dockerfile Instructions VOLUME [“<mount-point>”...] or VOLUME <mount-point> - Creates a

    mount point with the specified name - Marks it as holding externally mounted volumes from native host or other containers - If any build steps change the data within the volume after it has been declared, those changes will be discarded. - Host directory cannot be specified in Dockerfile. FROM ubuntu RUN mkdir /myvol RUN echo "hello world" > /myvol/greeting VOLUME /myvol example 1 2 3
  67. Dockerfile Instructions VOLUME [“<mount-point>”...] or VOLUME <mount-point> - Creates a

    mount point with the specified name - Marks it as holding externally mounted volumes from native host or other containers - If any build steps change the data within the volume after it has been declared, those changes will be discarded. - Host directory cannot be specified in Dockerfile. FROM ubuntu RUN mkdir /myvol RUN echo "hello world" > /myvol/greeting VOLUME /myvol example 1 2 3 4
  68. Dockerfile Instructions WORKDIR /path/to/workdir - sets the working directory for

    any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in Dockerfile
  69. Dockerfile Instructions WORKDIR /path/to/workdir - sets the working directory for

    any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in Dockerfile FROM ubuntu ADD hello /myapp/hello WORKDIR /myapp ENTRYPOINT ./hello example
  70. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app
  71. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app Why Dockerize the build environment? - Team members can use their prefered style of working. - OS / Editor - While collaborating, should avoid “Works in my environment” - Test the program on local machine i.e. get binary back from container.
  72. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app Why Dockerize the build environment? - Team members can use their prefered style of working. - OS / Editor - While collaborating, should avoid “Works in my environment” - Test the program on local machine i.e. get binary back from container. Solution Dockerize the build environment
  73. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app
  74. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app How to Dockerize?
  75. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app How to Dockerize? - Identify Base Image (docker search ?)
  76. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app How to Dockerize? - Identify Base Image (docker search ?) - List down dependencies for your application.
  77. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app How to Dockerize? - Identify Base Image (docker search ?) - List down dependencies for your application. - Compiler?
  78. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app How to Dockerize? - Identify Base Image (docker search ?) - List down dependencies for your application. - Compiler? - Source Code… Mount or copy?
  79. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app How to Dockerize? - Identify Base Image (docker search ?) - List down dependencies for your application. - Compiler? - Source Code… Mount or copy? - CMD ?
  80. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app How to Dockerize? - Identify Base Image (docker search ?) - List down dependencies for your application. - Compiler? - Source Code… Mount or copy? - CMD ? FROM golang:1.8 RUN go get github.com/buger/goterm COPY . /vcoin VOLUME /vcoin WORKDIR /vcoin
  81. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app
  82. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app FROM golang:1.8 RUN go get github.com/buger/goterm COPY . /vcoin VOLUME /vcoin WORKDIR /vcoin
  83. Dockerize build for your application - Our Sample Application -

    https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app FROM golang:1.8 RUN go get github.com/buger/goterm COPY . /vcoin VOLUME /vcoin WORKDIR /vcoin dbuild: vcoinimage docker run --rm -v $(CURDIR):/vcoin $(BUILD_IMAGE) go build vcoinimage: docker build -t $(BUILD_IMAGE) .
  84. Now it’s Your Turn!! - Identify Base image (docker store)

    - List down dependencies for your application. - Compiler? - Application… Mount or copy? - CMD ? - Dockerfile - Makefile or equivalent
  85. Running application in container. Why you want to run application

    in container? - Cross platform application - Test in consistent environment. - Test in multiple environment cheaply.
  86. Running application in container. Things to consider. - Base Image

    - Application binary/source - Network & Ports - Output - Log / Debug? Why you want to run application in container? - Cross platform application - Test in consistent environment. - Test in multiple environment cheaply.
  87. Running application in container. Things to consider. - Base Image

    - Application binary/source - Network & Ports - Output - Log / Debug? Why you want to run application in container? - Cross platform application - Test in consistent environment. - Test in multiple environment cheaply. FROM golang:1.8 RUN go get github.com/buger/goterm COPY . /vcoin VOLUME /vcoin WORKDIR /vcoin
  88. Running application in container. Things to consider. - Base Image

    - Application binary/source - Network & Ports - Output - Log / Debug? Why you want to run application in container? - Cross platform application - Test in consistent environment. - Test in multiple environment cheaply. FROM golang:1.8 RUN go get github.com/buger/goterm COPY . /vcoin VOLUME /vcoin WORKDIR /vcoin dbuild: vcoinimage docker run --rm -v $(CURDIR):/vcoin $(BUILD_IMAGE) go run main.go vcoinimage: docker build -t $(BUILD_IMAGE) .
  89. Running application in container. Things to consider. - Base Image

    - Application binary/source - Network & Ports - Output - Log / Debug? Why you want to run application in container? - Cross platform application - Test in consistent environment. - Test in multiple environment cheaply. FROM golang:1.8 RUN go get github.com/buger/goterm COPY . /vcoin VOLUME /vcoin WORKDIR /vcoin dbuild: vcoinimage docker run --rm -v $(CURDIR):/vcoin $(BUILD_IMAGE) go run main.go vcoinimage: docker build -t $(BUILD_IMAGE) .
  90. Debugging inside container Running application in any environment is meaningless

    if you can’t debug it! Remember! - Containers are OS processes running in some namespaces. - Your application is still accessible, just enter the namespace :)
  91. Debugging inside container Running application in any environment is meaningless

    if you can’t debug it! Remember! - Containers are OS processes running in some namespaces. - Your application is still accessible, just enter the namespace :) - Adapting containers does not change your original workflow. - You continue using your existing debugging mechanism
  92. Debugging inside container Running application in any environment is meaningless

    if you can’t debug it! Remember! - Containers are OS processes running in some namespaces. - Your application is still accessible, just enter the namespace :) - Adapting containers does not change your original workflow. - You continue using your existing debugging mechanism docker exec
  93. Debugging inside container Running application in any environment is meaningless

    if you can’t debug it! Remember! - Containers are OS processes running in some namespaces. - Your application is still accessible, just enter the namespace :) - Adapting containers does not change your original workflow. - You continue using your existing debugging mechanism docker exec - Enter namespace
  94. Debugging inside container Running application in any environment is meaningless

    if you can’t debug it! Remember! - Containers are OS processes running in some namespaces. - Your application is still accessible, just enter the namespace :) - Adapting containers does not change your original workflow. - You continue using your existing debugging mechanism docker exec - Enter namespace - Install required tool
  95. Debugging inside container Running application in any environment is meaningless

    if you can’t debug it! Remember! - Containers are OS processes running in some namespaces. - Your application is still accessible, just enter the namespace :) - Adapting containers does not change your original workflow. - You continue using your existing debugging mechanism docker exec - Enter namespace - Install required tool - Use it :)
  96. Debugging inside container Running application in any environment is meaningless

    if you can’t debug it! Remember! - Containers are OS processes running in some namespaces. - Your application is still accessible, just enter the namespace :) - Adapting containers does not change your original workflow. - You continue using your existing debugging mechanism docker exec - Enter namespace - Install required tool - Use it :) Useful docker commands ! $ docker logs <container-id> ! $ docker stats
  97. Debugging inside container Let’s enhance our sample application. - git

    merge origin/bug # This adds some UI fix - Use docker exec to debug.
  98. Debugging inside container Let’s enhance our sample application. - git

    merge origin/bug # This adds some UI fix - Use docker exec to debug. - Check log.txt
  99. Debugging inside container Let’s enhance our sample application. - git

    merge origin/bug # This adds some UI fix - Use docker exec to debug. - Check log.txt
  100. Debugging inside container Let’s enhance our sample application. - git

    merge origin/bug # This adds some UI fix - Use docker exec to debug. - Check log.txt - git merge origin bug-fix # Fix’s the bug
  101. Distributing application as docker containers. Why? - Bundle application with

    dependencies. - No environment configuration required with every new release - Easy upgradation - Easy distribution using docker hub/registry. - Just like git for Docker images - A dev environment that has exactly the same dependencies as the production one
  102. But... How to reduce size of Image? - Base Image?

    Choose better base image. - No unwanted software packages (Storage is Cheap, but Security is not)
  103. Multi stage build Current pain point. - Build app in

    one container. - Build new container for distribution (smaller)
  104. Multi stage build Current pain point. - Build app in

    one container. - Build new container for distribution (smaller) - Muti-stage build solves the problem
  105. Multi stage build Current pain point. - Build app in

    one container. - Build new container for distribution (smaller) - Muti-stage build solves the problem - Available in docker v17.06 onwards
  106. Multi stage build Current pain point. - Build app in

    one container. - Build new container for distribution (smaller) - Muti-stage build solves the problem - Available in docker v17.06 onwards FROM golang:1.8 RUN go get github.com/buger/goterm COPY . /vcoin VOLUME /vcoin WORKDIR /vcoin CMD ["go", "build"] FROM alpine:latest WORKDIR /root/ COPY --from=0 /vcoin/vcoin . CMD ["./vcoin"]
  107. Multi stage build Current pain point. - Build app in

    one container. - Build new container for distribution (smaller) - Muti-stage build solves the problem - Available in docker v17.06 onwards FROM golang:1.8 RUN go get github.com/buger/goterm COPY . /vcoin VOLUME /vcoin WORKDIR /vcoin CMD ["go", "build"] FROM alpine:latest WORKDIR /root/ COPY --from=0 /vcoin/vcoin . CMD ["./vcoin"]
  108. Multi stage build Current pain point. - Build app in

    one container. - Build new container for distribution (smaller) - Muti-stage build solves the problem - Available in docker v17.06 onwards FROM golang:1.8 RUN go get github.com/buger/goterm COPY . /vcoin VOLUME /vcoin WORKDIR /vcoin CMD ["go", "build"] FROM alpine:latest WORKDIR /root/ COPY --from=0 /vcoin/vcoin . CMD ["./vcoin"]
  109. Things to Look & try further ! - Docker networking

    - Docker Compose - Docker swarm-mode