“Containerizing” applications with Docker: Ecosystem and Tools
Containerizing Your Dev Environment
-
Upload
laura-frank -
Category
Technology
-
view
268 -
download
1
Transcript of Containerizing Your Dev Environment
Containerizing Your Dev Environment
Laura Frank
rheinwein
@rhein_wein
rheinwein/hello-world-container-demo
Containerization: what even is it?
Setting up a dev environment
Docker ecosystem nuts and bolts
A tool for managing containers
• Managing code that goes in them • Executing code inside of them
• Run in a self-contained execution environment • Share the kernel of host system • Are isolated from other containers • Have fast boot times & low overhead
Containers
A container is a virtualization layer — sort of like a VM — but with some fundamental differences
hardware
host OS
hypervisor
$ guest OS
libraries
app 1
$ guest OS $ guest OS
libraries
app 2
libraries
app 1
libraries
app 1
libraries
app 2
hardware
host OS
libraries
app 1
hardware
host OS
container runtime engine
libraries libraries
app 1 app 1 app 2
Containers have slightly more complexity
but
They reduce the amount of time/space resources needed to run your application
• It’s fast! • It’s cheap! • It’s portable! • It’s safe!
Benefits of Containerization
A Bird’s Eye View of Docker
A tool for managing containers
• Managing code that goes in them • Executing code inside of them
Engine Hub
docker.com
registry.hub.docker.com
Interacting with the Registry
• Push and pull —just like GitHub • Two types of images
• Services • Project base images
Private Registries
• Get setup image from Docker Registry • Can have authentication • Push and pull just like with Docker Hub
A tool for managing containers
• Managing code that goes in them
• Executing code inside of them
hardware
host OS
container runtime engine
libraries libraries
app 1 app 1 app 2
• docker run my_image • docker pull your_image • docker images • docker ps
Docker CLI
• Docker daemon runs with each container
• Daemon exposes API with RESTful endpoints
• Using CLI == using API, just abstracted • You could build your own tooling
Docker API
Setting Up Your Dev Environment with Docker
Objectives
• Put code in container • Run the code inside the container • See application in web browser
• A computer* • Code to run • Coffee (if you’d like)
Things you need
Installing Docker
Anything else? You need to use a lightweight VM.
Pro Tip: Boot2Docker (OSX and Windows)
Linux? Install Docker with official packages.
A Computer
• Linked folders • Copied files • Port forwarding
Handling Abstraction
Code may seem out of reach, but can be managed using
An image is controlled by a Dockerfiledocker build -t foo/bar .
docker pull foo/bar
Code to Run
All containers are based on images
Code to Run
• Static: all files and code are contained in image
• Dynamic: link folders to actively modify code (development only)
SEHR WICHTIG!
FROM centurylink/ruby-base:2.1.2
MAINTAINER Laura Frank <[email protected]>
EXPOSE 4567
RUN mkdir -p /usr/src/app ADD . /usr/src/app
WORKDIR /usr/src/app RUN bundle install
CMD “ruby hello_world.rb"
Dockerfile
FROM centurylink/ruby-base:2.1.2
MAINTAINER Laura Frank <[email protected]>
EXPOSE 4567
RUN mkdir -p /usr/src/app ADD . /usr/src/app
WORKDIR /usr/src/app RUN bundle install
CMD “ruby hello_world.rb"
Dockerfile
FROM centurylink/ruby-base:2.1.2
MAINTAINER Laura Frank <[email protected]>
EXPOSE 4567
RUN mkdir -p /usr/src/app ADD . /usr/src/app
WORKDIR /usr/src/app RUN bundle install
CMD “ruby hello_world.rb"
Dockerfile
This copies code into the container
STATIC! Not for apps under active development
Great for dependencies and production applications
FROM centurylink/ruby-base:2.1.2
MAINTAINER Laura Frank <[email protected]>
EXPOSE 4567
RUN mkdir -p /usr/src/app ADD . /usr/src/app
WORKDIR /usr/src/app RUN bundle install
CMD “ruby hello_world.rb"
Dockerfile
This makes things happen to your code
FROM centurylink/ruby-base:2.1.2
MAINTAINER Laura Frank <[email protected]>
EXPOSE 4567
RUN mkdir -p /usr/src/app ADD . /usr/src/app
WORKDIR /usr/src/app RUN bundle install
CMD “ruby hello_world.rb"
Dockerfile
This makes the code happen
FROM centurylink/ruby-base:2.1.2
No need for version management, just use a different base image.
Base images are great!
Dockerfile
• Available on Docker Hub • Maintained by other people (laziness++) • Repositories includes instructions for
bootstrapping • Images can be base images or actually
run services
Official Images
The Easy Way: Boot2Docker
• Creates folder links for you • Obscures the separation between VM and
host • Super handy for quick, small projects • Not great for more complex systems
The Hard Way: Vagrant
• Manually create folder links • Choose your own OS • Must ssh into VM • Great for more customization
The Hard Way: Vagrant
config.vm.box_url = "http://storage.core-os.net/coreos/amd64-usr/alpha/coreos_production_vagrant.json"
config.vm.synced_folder "/Users/lfrank/CTL/panamax/panamax-api", "/var/panamax-api", id: "core", nfs: "true", mount_options: ['nolock,vers=3,udp']
Either Way• Remember to forward ports in order to
access app in a browser
-p host_port:container_port
(Sorry.)
…is kind of a pain.
Debugging in a Container
Use a remote debugger.
Debugging in a Container
If you’re a Rubyist, use Pry
require ‘pry’
class Thing def some_method binding.pry #some brilliant broken code end end
Debugging in a Container
Application Templating
• Use your own images, or images from the Docker Registry
• Specify config options beforehand (like port forwarding)
• Run applications with one or two simple commands
Standards tightly coupled with Docker
fig.sh
Dump requirements into fig.yml and run with fig up
Docker workflow tool
Itself a containerized application
panamax.io
Uses CoreOS, Fleet, and etcd for orchestration and service discovery
Templating language similar to fig
Supports remote deployments
panamax.io/get-panamax
--- name: Rails with PostgreSQL description: Rails with PostgreSQL
images: - category: Web Tier name: Rails source: rheinwein/rails:latest description: Rails App type: Default expose: [] ports: - host_port: '8080' container_port: '3000' links: - service: Database alias: DB_1 environment: [] volumes: []
–Johnny Appleseed
“Type a quote here.”
Additional Resources
Docker Hub: registry.hub.docker.com
Documentation: docs.docker.com
Boot2Docker: boot2docker.io
Panamax: panamax.io
CenturyLink Labs: centurylinklabs.com
Thanks!
Laura Frank
rheinwein
@rhein_wein