Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Docker: From Zero to Hero


Published on

...or how to start your adventure with Docker. Promises, goals and practical examples by one of our devs, Tomasz. Visit our blog for more!

Published in: Technology
  • Be the first to comment

Docker: From Zero to Hero

  2. 2. INTRODUCTION PROMISES ▸ isolation ▸ lightness ▸ repeatability ▸ speed ▸ easy collaboration ▸ easy configuration
  4. 4. INTRODUCTION TECHNOLOGIES ▸ LXC - Linux Containers - process isolation ▸ UnionFS - layered file system ▸ Go - programming language LINUX UNION FS LXC DOCKER (GO)
  5. 5. ▸ container - run ▸ image - build ▸ registry - pull/push INTRODUCTION TERMS AND OPERATIONS
  6. 6. EXAMPLE MINECRAFT SERVER # Minecraft 1.8.7 Dockerfile - Example with notes # Use the offical Debian Docker image with a specified version tag, Wheezy, so not all # versions of Debian images are downloaded. FROM debian:wheezy # Use APT (Advanced Packaging Tool) built in the Linux distro to download Java, a dependency to run Minecraft. RUN apt-get -y update RUN apt-get -y install openjdk-7-jre-headless wget # Download Minecraft Server components RUN wget -q minecraft_server.1.9.2.jar # Sets working directory for the CMD instruction (also works for RUN, ENTRYPOINT commands) # Create mount point, and mark it as holding externally mounted volume WORKDIR /data VOLUME /data # Expose the container's network port: 25565 during runtime. EXPOSE 25565 #Automatically accept Minecraft EULA, and start Minecraft server CMD echo eula=true > /data/eula.txt && java -jar /minecraft_server.1.9.2.jar
  8. 8. DEMO WHAT’S THE GOAL ▸ bpasik’s Node.js app with Mongo DB running on Docker TOOLS REFERENCE ▸ Docker hub ▸ Dockerfile ▸ Docker compose

  9. 9. DEMO BUILD IT # Dockerfile FROM node:onbuild EXPOSE 3000 RUN IT # run mongo as daemon container and expose it’s 27017 port to localhost’s 27017 # WARNING: on Windows or OS X Docker is not running on localhost # it’s running on boot2docker VM with it’s own IP # so it’s exposing this port as e.g. # (this also means you’d have to embed this IP into config/default.json) $ docker run -d -p 27017:27017 mongo << mongo container id here>> # build our app Docker image and tag it as node-app $ docker build -t node-app . << lots of logs here >> # run mongo as daemon and expose container’s port 3000 to localhost’s 3000 $ docker run -d -p 3000:3000 node-app << node-app container id here>> # you can now access localhost:3000 and see the running containers $ docker ps
  10. 10. DEMO BUT RUNNING IT BY HAND EACH TIME IS UNCOOL… # WARNING: remove all containers (running and stopped) $ docker ps -qa | xargs docker rm -f Cleanup Declarative docker compose configuration # docker-compose.yml version: '2' services: web: # use our Dockerfile build: . # expose the port 3000 ports: - "3000:3000" links: # link the mongo container under hostname 'mongo' # remember to change config/default.json to use mongo:27017 - mongo mongo: image: mongo $ docker-compose up # try changing public/index.html and refresh the page Run it!
  11. 11. DEMO WHAT IF WE WANT TO EDIT LIVE FILES? $ docker-compose down Cleanup (the docker-compose way) Change our Dockerfile to use other base image # Dockerfile FROM node EXPOSE 3000 # point to our volume (where the app is mounted) WORKDIR /app # start with the app’s start command CMD [ "npm", "start" ] $ docker-compose up # try changing public/index.html again and see the changes live Run it! Change our docker-compose.yml to use a volume version: '2' services: web: build: . ports: - "3000:3000" # mount . directory to container’s /app volumes: - .:/app links: - mongo mongo: image: mongo
  12. 12. DEMO SUMMING UP ▸ we’ve started from running containers by hand ▸ defined Docker compose config with linked containers ▸ changed the app embedded in the image to be mounted as a volume ▸ Dockerization available in my fork of the app: Examples