Slide 1

Slide 1 text

Docker Workshop for Developers Kunal Kushwaha @kunalkushwaha @DockerTokyo

Slide 2

Slide 2 text

Docker Workshop for Developers Kunal Kushwaha @kunalkushwaha @DockerTokyo

Slide 3

Slide 3 text

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.

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

Information Sample Source Code: https://github.com/docker-meetup-tokyo/workshop

Slide 6

Slide 6 text

Docker for Developers

Slide 7

Slide 7 text

Docker for Developers - Do we gonna learn new workflow?

Slide 8

Slide 8 text

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.

Slide 9

Slide 9 text

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?

Slide 10

Slide 10 text

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.

Slide 11

Slide 11 text

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.

Slide 12

Slide 12 text

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.

Slide 13

Slide 13 text

Docker Docker is container platform, which provides all tooling for end to end solutions for software development, distribution, deployment & management. “Build, Ship, Run anywhere”

Slide 14

Slide 14 text

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”

Slide 15

Slide 15 text

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”

Slide 16

Slide 16 text

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”

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

VM vs Docker

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Docker Architecture

Slide 21

Slide 21 text

Docker CLI

Slide 22

Slide 22 text

Docker CLI $ docker

Slide 23

Slide 23 text

Docker CLI $ docker

Slide 24

Slide 24 text

Docker CLI $ docker Our Target

Slide 25

Slide 25 text

Docker CLI $ docker Our Target - Most of subcommands under “container” & “image” are available as docker too!

Slide 26

Slide 26 text

Docker CLI

Slide 27

Slide 27 text

Docker CLI $docker pull [:]

Slide 28

Slide 28 text

Docker CLI $docker pull [:] $docker pull hello-world

Slide 29

Slide 29 text

Docker CLI $docker pull [:] $docker pull hello-world

Slide 30

Slide 30 text

Docker CLI $docker pull [:] $docker pull hello-world

Slide 31

Slide 31 text

Docker CLI $docker pull [:] $docker pull hello-world

Slide 32

Slide 32 text

Docker CLI $docker pull [:] $docker pull hello-world Default tag

Slide 33

Slide 33 text

Docker CLI $docker pull [:] $docker pull hello-world Default tag SHA256 Digest

Slide 34

Slide 34 text

Docker CLI $docker pull [:] $docker pull hello-world Default tag SHA256 Digest

Slide 35

Slide 35 text

Docker CLI $docker pull [:] $docker pull hello-world Default tag SHA256 Digest

Slide 36

Slide 36 text

Docker CLI

Slide 37

Slide 37 text

Docker CLI $docker run [image-name>:]

Slide 38

Slide 38 text

Docker CLI $docker run [image-name>:] $docker run hello-world

Slide 39

Slide 39 text

Docker CLI $docker run [image-name>:] $docker run hello-world

Slide 40

Slide 40 text

Docker CLI $docker run [image-name>:] $docker run hello-world

Slide 41

Slide 41 text

Docker CLI $docker run [image-name>:] $docker run hello-world

Slide 42

Slide 42 text

Docker CLI

Slide 43

Slide 43 text

Docker CLI $ docker run -it alpine sh

Slide 44

Slide 44 text

Docker CLI $ docker run -it alpine sh

Slide 45

Slide 45 text

Docker CLI $ docker run -it alpine sh

Slide 46

Slide 46 text

Docker CLI $ docker run -it alpine sh Interactive & Assign a terminal

Slide 47

Slide 47 text

Docker CLI $ docker run -it alpine sh Interactive & Assign a terminal

Slide 48

Slide 48 text

Docker CLI $ docker run -it alpine sh Interactive & Assign a terminal

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

Docker Cli

Slide 56

Slide 56 text

Docker Cli $docker ps

Slide 57

Slide 57 text

Docker Cli $docker ps $docker ps -a

Slide 58

Slide 58 text

Docker Cli $docker ps $docker ps -a

Slide 59

Slide 59 text

Docker Cli $docker ps $docker ps -a

Slide 60

Slide 60 text

Docker Cli $docker ps $docker ps -a Unique ID 64 hex string

Slide 61

Slide 61 text

Docker Cli $docker ps $docker ps -a Unique ID 64 hex string Image

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

Docker Cli $docker ps $docker ps -a Unique ID 64 hex string Image Starting command Names automatically assigned if not provided

Slide 66

Slide 66 text

Docker Cli $docker exec [container-name| id]

Slide 67

Slide 67 text

Docker Cli $docker exec -it test sh $docker exec [container-name| id]

Slide 68

Slide 68 text

Docker Cli $docker exec -it test sh $docker exec [container-name| id]

Slide 69

Slide 69 text

Docker Cli $docker exec -it test sh $docker exec [container-name| id]

Slide 70

Slide 70 text

Docker Cli $docker exec -it test sh Interactive & Assign a terminal $docker exec [container-name| id]

Slide 71

Slide 71 text

Docker Cli $docker exec -it test sh Interactive & Assign a terminal $docker exec [container-name| id]

Slide 72

Slide 72 text

Docker Cli $docker exec -it test sh Interactive & Assign a terminal $docker exec [container-name| id]

Slide 73

Slide 73 text

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

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

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

Slide 79

Slide 79 text

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

Slide 80

Slide 80 text

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

Slide 81

Slide 81 text

Docker CLI $ docker logs - 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 - Deletes the container (works on non-running containers only) $ docker rmi - Deletes the image (If image have no reference)

Slide 82

Slide 82 text

Building Application in Containers

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

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

Slide 85

Slide 85 text

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.

Slide 86

Slide 86 text

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.

Slide 87

Slide 87 text

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.

Slide 88

Slide 88 text

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.

Slide 89

Slide 89 text

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.

Slide 90

Slide 90 text

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.

Slide 91

Slide 91 text

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.

Slide 92

Slide 92 text

Dockerfile Instructions FROM [image]: - 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.

Slide 93

Slide 93 text

Dockerfile Instructions FROM [image]: - 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

Slide 94

Slide 94 text

Dockerfile Instructions FROM [image]: - 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

Slide 95

Slide 95 text

Dockerfile Instructions FROM [image]: - 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/

Slide 96

Slide 96 text

Dockerfile Instructions RUN 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.

Slide 97

Slide 97 text

Dockerfile Instructions RUN 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

Slide 98

Slide 98 text

Dockerfile Instructions RUN 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 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

Slide 99

Slide 99 text

Dockerfile Instructions RUN 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 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

Slide 100

Slide 100 text

Dockerfile Instructions ENV ENV = ... - Sets the environment variable to the value

Slide 101

Slide 101 text

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

Slide 102

Slide 102 text

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

Slide 103

Slide 103 text

Dockerfile Instructions COPY ... or ADD [“”,.. “”] - 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.

Slide 104

Slide 104 text

Dockerfile Instructions COPY ... or ADD [“”,.. “”] - 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.

Slide 105

Slide 105 text

Dockerfile Instructions

Slide 106

Slide 106 text

Dockerfile Instructions VOLUME [“”...] or VOLUME - 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.

Slide 107

Slide 107 text

Dockerfile Instructions VOLUME [“”...] or VOLUME - 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

Slide 108

Slide 108 text

Dockerfile Instructions VOLUME [“”...] or VOLUME - 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

Slide 109

Slide 109 text

Dockerfile Instructions VOLUME [“”...] or VOLUME - 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

Slide 110

Slide 110 text

Dockerfile Instructions VOLUME [“”...] or VOLUME - 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

Slide 111

Slide 111 text

Dockerfile Instructions VOLUME [“”...] or VOLUME - 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

Slide 112

Slide 112 text

Dockerfile Instructions VOLUME [“”...] or VOLUME - 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

Slide 113

Slide 113 text

Dockerfile Instructions VOLUME [“”...] or VOLUME - 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

Slide 114

Slide 114 text

Dockerfile Instructions VOLUME [“”...] or VOLUME - 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

Slide 115

Slide 115 text

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

Slide 116

Slide 116 text

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

Slide 117

Slide 117 text

Let’s try hands-on

Slide 118

Slide 118 text

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

Slide 119

Slide 119 text

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.

Slide 120

Slide 120 text

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

Slide 121

Slide 121 text

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

Slide 122

Slide 122 text

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

Slide 123

Slide 123 text

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 ?)

Slide 124

Slide 124 text

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.

Slide 125

Slide 125 text

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?

Slide 126

Slide 126 text

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?

Slide 127

Slide 127 text

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 ?

Slide 128

Slide 128 text

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

Slide 129

Slide 129 text

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

Slide 130

Slide 130 text

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

Slide 131

Slide 131 text

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) .

Slide 132

Slide 132 text

Demo

Slide 133

Slide 133 text

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

Slide 134

Slide 134 text

Running application in container. Why you want to run application in container? - Cross platform application - Test in consistent environment. - Test in multiple environment cheaply.

Slide 135

Slide 135 text

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.

Slide 136

Slide 136 text

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

Slide 137

Slide 137 text

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) .

Slide 138

Slide 138 text

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) .

Slide 139

Slide 139 text

Demo

Slide 140

Slide 140 text

Debugging inside container

Slide 141

Slide 141 text

Debugging inside container Running application in any environment is meaningless if you can’t debug it!

Slide 142

Slide 142 text

Debugging inside container Running application in any environment is meaningless if you can’t debug it! Remember!

Slide 143

Slide 143 text

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 :)

Slide 144

Slide 144 text

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

Slide 145

Slide 145 text

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

Slide 146

Slide 146 text

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

Slide 147

Slide 147 text

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

Slide 148

Slide 148 text

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 :)

Slide 149

Slide 149 text

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 ! $ docker stats

Slide 150

Slide 150 text

Debugging inside container

Slide 151

Slide 151 text

Debugging inside container Let’s enhance our sample application.

Slide 152

Slide 152 text

Debugging inside container Let’s enhance our sample application. - git merge origin/bug # This adds some UI fix

Slide 153

Slide 153 text

Debugging inside container Let’s enhance our sample application. - git merge origin/bug # This adds some UI fix

Slide 154

Slide 154 text

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

Slide 155

Slide 155 text

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

Slide 156

Slide 156 text

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

Slide 157

Slide 157 text

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

Slide 158

Slide 158 text

Demo

Slide 159

Slide 159 text

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

Slide 160

Slide 160 text

But... How to reduce size of Image? - Base Image? Choose better base image. - No unwanted software packages (Storage is Cheap, but Security is not)

Slide 161

Slide 161 text

Multi stage build

Slide 162

Slide 162 text

Multi stage build Current pain point.

Slide 163

Slide 163 text

Multi stage build Current pain point. - Build app in one container.

Slide 164

Slide 164 text

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

Slide 165

Slide 165 text

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

Slide 166

Slide 166 text

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

Slide 167

Slide 167 text

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"]

Slide 168

Slide 168 text

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"]

Slide 169

Slide 169 text

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"]

Slide 170

Slide 170 text

Things to Look & try further ! - Docker networking - Docker Compose - Docker swarm-mode

Slide 171

Slide 171 text

ありがとう Thanks