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

Django & Docker

Django & Docker

How to be happy with Django & Docker @djangovillage2014

barrachri

June 13, 2014
Tweet

More Decks by barrachri

Other Decks in Programming

Transcript

  1. Django & Docker
    How to be happy with Django & Docker

    View Slide

  2. Hi there !
    My name is Christian
    @christianbarra

    View Slide

  3. Quick survey
    • How many people have heard about docker ?
    • How many people have tried docker ?
    • How many people are using docker ?

    View Slide

  4. Let’s go !

    View Slide

  5. !
    it’s all heavily
    under construction !

    View Slide

  6. The (big) problem

    View Slide

  7. Deployment sucks !

    View Slide

  8. Our Noah’s ark
    (from Tokyo Docker Meetup)

    View Slide

  9. What is Docker ?

    View Slide

  10. Definition
    Docker is an open-source platform for developing,
    shipping, and running applications.
    Is fast, lightweight and portable and you can separate
    your applications from your infrastructure.
    Docker combining a lightweight container virtualization
    platform with workflows and tooling that help you
    manage and deploy your applications.

    View Slide

  11. Docker is not a VM

    View Slide

  12. The little story
    • Dotcloud inc. (PaaS) -> Docker inc.
    • Initially written in python -> now in GO
    • 1.0 is out !
    • Initially based on LinuX Container (LXC) now it uses
    libcontainer

    View Slide

  13. How it works
    3 main components:
    !
    • Docker server daemon
    • Docker API/client (CLI - command line interface)
    • Docker registry (official, private and public)
    !
    The Docker API/client and Docker server
    communicate via sockets or through a RESTful API.

    View Slide

  14. Why use Docker ?

    View Slide

  15. Well…. Docker is:
    • Lightweight
    • Minimal resources -> Minimal overhead
    • Fast
    • Portable
    • Open Source
    • Easy

    View Slide

  16. How to install Docker

    View Slide

  17. Requirements
    • 64bit
    • LXC (not anymore with libcontainer)
    • AUFS
    • Linux 3.8 or above
    !
    Available for : Linux, Mac OS X (with boot2docker),
    soon for other Unix OS.

    View Slide

  18. $ sudo apt-get update
    $ sudo apt-get install linux-image-
    extra-`uname -r`
    ---------------------
    $ curl -s https://get.docker.io/
    ubuntu/ | sudo sh
    !
    !
    !
    Other OS at:
    http://docs.docker.com/

    View Slide

  19. Docker components

    View Slide

  20. Docker server
    • The Docker daemon runs on a host machine.
    • It can be LOCAL or REMOTE
    • He managed CONTAINERS and IMAGE
    • The user does not directly interact with the daemon,
    but instead through the Docker API/client.

    View Slide

  21. Docker API/client
    • Is the primary user interface to Docker
    • It accepts commands from the user and
    communicates back and forth with a Docker
    daemon.

    View Slide

  22. Docker registry
    It’s simple the Docker images repository
    !
    It can be:
    • Official: hub.docker.com (private and public)
    • Others (private and public)
    !
    !
    docker-registry repository
    https://github.com/dotcloud/docker-registry

    View Slide

  23. Now our best friends
    IMAGE
    &
    CONTAINER

    View Slide

  24. Docker image
    A Docker image is a read-only “template”.
    !
    For example, an image could contain an Ubuntu operating
    system with Apache, NGINX or your database.
    !
    Images are used to create Docker containers.
    !
    You can:
    • build new images
    • update existing images
    • download Docker images already created.

    View Slide

  25. Docker container 1/2
    Docker containers are similar to a directory.
    !
    A Docker container holds everything that is needed for an
    application to run and can be run, started, stopped, moved,
    and deleted.
    !
    Each container is an isolated and secure application platform.
    !
    A container consists of an operating system, user-added files,
    and meta-data.

    View Slide

  26. Docker container 2/2
    An image tells Docker what the container holds, what
    process to run when the container is launched, and a
    variety of other configuration data.
    !
    When Docker runs a container from an image, it adds
    a read-write layer on top of the image (using a union
    file system) in which your application can then run.

    View Slide

  27. Docker flow
    1.Build/Download your Docker images
    2.Create (alias run) your container from those images
    3.Share/Save your images on Docker Hub or your
    own repository

    View Slide

  28. View Slide

  29. Docker CLI
    alias Docker Command Line Interface

    View Slide

  30. docker [OPTIONS] COMMAND [arg]
    docker.io in ubuntu 14.04

    View Slide

  31. Some commands
    docker run # run a container
    docker stop # stop a container
    docker rm # remove a container
    docker rmi # remove an image
    docker inspect # information about container
    docker commit # create a new image from the container
    docker logs # container’s logs
    docker build # build a container from a dockerfile
    docker ps # lists the container
    docker pull # pull an image from a registry

    View Slide

  32. docker run [OPTIONS]
    IMAGE[:TAG] [COMMAND] [ARG]
    Run a command in a new container starting from an image

    View Slide

  33. Example #1
    docker run

    View Slide

  34. docker run ubuntu echo “ciao”
    run a container based on ubuntu image with command echo
    “ciao”
    !
    [email protected]:~# docker run ubuntu echo "ciao"
    Unable to find image 'ubuntu' locally # looks for ubuntu image
    locally
    Pulling repository ubuntu # pull ubuntu image from
    hub.docker.com
    a7cf8ae4e998: Download complete
    ……………………………………………………
    4d26dd3ebc1c: Download complete
    d4010efcfd86: Download complete
    ciao # output of our COMMAND

    View Slide

  35. Some run options
    -d # Detached mode (alias background)
    -e # Set environment variables
    -h # Container host name
    -p # Publish a container's port to the host
    -v, --volume=[] #Bind mount a volume
    --link #Add link to another container (name:alias)
    --volumes-from=[] #Mount volumes from the specified
    container(s)
    -m, --memory=”” #Memory limit
    -c #CPU shares (relative weight)

    View Slide

  36. Example #2
    docker run

    View Slide

  37. docker run -v /var/log -p 80:80 --name
    nginx_c ubuntu touch /var/log/text
    -v /var/log # mount dir outside container
    -p 80:80 # redirect 80 port of host machine to 80
    port of container
    --name nginx_c # name this container nginx_c
    touch /var/log/text # our COMMAND with [ARG]

    View Slide

  38. docker inspect CONTAINER|IMAGE
    [CONTAINER|IMAGE]
    Return information on a container/image

    View Slide

  39. docker logs [OPTIONS]
    CONTAINER
    Fetch the logs of a container

    View Slide

  40. docker ps [OPTIONS]
    List containers

    View Slide

  41. docker build [OPTIONS] PATH |
    URL | -
    Build an image from a Dockerfile

    View Slide

  42. Docker CLI reference
    http://docs.docker.com/reference/commandline/cli/

    View Slide

  43. Dockerfiles
    alias how to automate building of images

    View Slide

  44. This is a Dockerfile
    FROM ubuntu:12.04 # sets the base image
    RUN apt-get update # run a command
    RUN apt-get install -y build-essential git python /
    python-dev python-setuptools python-pip
    ADD ./ /app # copy files from host machine to images
    RUN pip install -r /app/requirements.txt
    VOLUME /app # In this way you can see this dir from your host machine
    EXPOSE 8080 # Port to expose
    CMD ["/usr/local/bin/uwsgi" ,"--ini" ,"/app/conf/uwsgi.ini"] # default command that will
    run when container starts

    View Slide

  45. But remember….
    Every RUN is a commit that save the state of the
    container into an image
    !
    RUN cd /var/log
    RUN rm mylogs
    !
    is different from
    !
    RUN cd /var/log && rm mylogs

    View Slide

  46. Dockerfile cache
    Every line in your Dockerfile is chached, if you change
    one line Docker will build your image from that line.

    View Slide

  47. Dockerfile docs
    reference
    http://docs.docker.com/reference/builder/

    View Slide

  48. What sucks (for me)
    Manage many containers
    alias orchestration

    View Slide

  49. View Slide

  50. Interesting projects
    • Dokku - Heroku with Docker
    • Orchard - PaaS provider for Docker
    • CoreOS - OS for Docker cloud server
    • Maestro - Orchestration system for Docker
    • Apache Mesos - From the name it seems awesome
    • Flynn.io - PaaS provider for Docker
    • Deis.io - PaaS provider for Docker
    • Other - A lot of other interesting stuff

    View Slide

  51. Resources to start
    Learn Docker in 10 min
    http://www.docker.com/tryit/
    !
    How is Docker.io different from a normal VM ?
    http://stackoverflow.com/questions/16047306/how-is-docker-io-
    different-from-a-normal-virtual-machine
    !
    Can you explain Docker with a practical example/case ?
    http://stackoverflow.com/questions/20618828/can-you-explain-docker-
    with-a-practical-example-case
    !
    Docker Explained: How To Containerize Python Web Applications
    https://www.digitalocean.com/community/tutorials/docker-explained-how-
    to-containerize-python-web-applications
    !
    !

    View Slide

  52. Community
    !
    official web site: www.docker.com
    irc: #docker on freenode
    google groups: docker-user
    italian meetup: (?)

    View Slide

  53. THANK YOU !
    @christianbarra
    www.chrisbarra.me
    slide: http://goo.gl/BihxmD

    View Slide