Share
Embed
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
Transcript
171 slides
-
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. -
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 -
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. -
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 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. -
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. -
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. -
Docker Docker is container platform, which provides all tooling for
end to end solutions for software development, distribution, deployment & management. “Build, Ship, Run anywhere” -
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” -
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” -
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” -
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 -
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 -
Docker CLI $ docker Our Target - Most of subcommands
under “container” & “image” are available as docker <command> too! -
Docker CLI $ docker run -it alpine sh Interactive &
Assign a terminal -
Docker CLI $ docker run -it alpine sh Interactive &
Assign a terminal -
Docker CLI $ docker run -it alpine sh Interactive &
Assign a terminal -
Docker CLI $ docker run -it alpine sh Interactive &
Assign a terminal Start container with this command( PID 1) -
Docker CLI $ docker run -it alpine sh Interactive &
Assign a terminal Start container with this command( PID 1) -
Docker CLI $ docker run -it alpine sh Interactive &
Assign a terminal Start container with this command( PID 1) -
Docker CLI $ docker run -it alpine sh Interactive &
Assign a terminal Start container with this command( PID 1) -
Docker CLI $ docker run -it alpine sh Interactive &
Assign a terminal Start container with this command( PID 1) -
Docker CLI $ docker run -it alpine sh Interactive &
Assign a terminal Start container with this command( PID 1) -
Docker Cli $docker ps $docker ps -a Unique ID 64
hex string Image -
Docker Cli $docker ps $docker ps -a Unique ID 64
hex string Image Starting command -
Docker Cli $docker ps $docker ps -a Unique ID 64
hex string Image Starting command -
Docker Cli $docker ps $docker ps -a Unique ID 64
hex string Image Starting command -
Docker Cli $docker ps $docker ps -a Unique ID 64
hex string Image Starting command Names automatically assigned if not provided -
Docker Cli $docker exec -it test sh $docker exec <flags>
[container-name| id] <command> -
Docker Cli $docker exec -it test sh $docker exec <flags>
[container-name| id] <command> -
Docker Cli $docker exec -it test sh $docker exec <flags>
[container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal $docker exec <flags> [container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal $docker exec <flags> [container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal $docker exec <flags> [container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal Executes command in container $docker exec <flags> [container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal Executes command in container $docker exec <flags> [container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal Executes command in container $docker exec <flags> [container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal Executes command in container $docker exec <flags> [container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal Executes command in container $docker exec <flags> [container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal Executes command in container $docker exec <flags> [container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal Executes command in container $docker exec <flags> [container-name| id] <command> -
Docker Cli $docker exec -it test sh Interactive & Assign
a terminal Executes command in container $docker exec <flags> [container-name| id] <command> -
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) -
Dockerfile. - A text document that contains all the commands
a user could call on the command line to assemble an image. -
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 -
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. -
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. -
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. -
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. -
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. -
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. -
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. -
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. -
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 -
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 -
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/ -
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. -
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 -
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 -
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 -
Dockerfile Instructions ENV <key> <value> ENV <key>=<value> ... - Sets
the environment variable <key> to the value <value> -
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 -
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. -
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. -
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. -
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. -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
Dockerfile Instructions WORKDIR /path/to/workdir - sets the working directory for
any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in Dockerfile -
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 -
Dockerize build for your application - Our Sample Application -
https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app -
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. -
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 -
Dockerize build for your application - Our Sample Application -
https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app -
Dockerize build for your application - Our Sample Application -
https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app How to Dockerize? -
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 ?) -
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. -
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? -
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? -
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 ? -
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 -
Dockerize build for your application - Our Sample Application -
https://github.com/docker-meetup-tokyo/workshop/tree/master/Docker4dev/sample-app -
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 -
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) . -
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 -
Running application in container. Why you want to run application
in container? - Cross platform application - Test in consistent environment. - Test in multiple environment cheaply. -
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. -
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 -
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) . -
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) . -
Debugging inside container Running application in any environment is meaningless
if you can’t debug it! -
Debugging inside container Running application in any environment is meaningless
if you can’t debug it! Remember! -
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 :) -
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 -
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 -
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 -
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 -
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 :) -
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 -
Debugging inside container Let’s enhance our sample application. - git
merge origin/bug # This adds some UI fix -
Debugging inside container Let’s enhance our sample application. - git
merge origin/bug # This adds some UI fix -
Debugging inside container Let’s enhance our sample application. - git
merge origin/bug # This adds some UI fix - Use docker exec to debug. -
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 -
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 -
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 -
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 -
But... How to reduce size of Image? - Base Image?
Choose better base image. - No unwanted software packages (Storage is Cheap, but Security is not) -
Multi stage build Current pain point. - Build app in
one container. -
Multi stage build Current pain point. - Build app in
one container. - Build new container for distribution (smaller) -
Multi stage build Current pain point. - Build app in
one container. - Build new container for distribution (smaller) - Muti-stage build solves the problem -
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 -
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"] -
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"] -
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"] -
Things to Look & try further ! - Docker networking
- Docker Compose - Docker swarm-mode