Docker 101 for Developers

A comprehensive guide for managing containers

PUG Torino - 22th February 2018

$: WHOAMI

uid=7(prometherion) gid=42(kiratech),groups=20(devops),12(developer),61(FATHERINHA),79(headbangingmusic),80(FORMULA1),81(kickboxing),98(bbq),702(cuisine),701(PIZZA)

PUG Torino - 22th February 2018

WHAT IS DOCKER?

Docker is a containerization tool used for spinning up isolated, reproducible application environments.

WHY CONTAINER?

Lightweight
uses the underlying host computer kernel

Distribution
easily distribute and recreate your entire development environment

Build once, run anywhere
no more (         ) environment-specific bugs

DOCKER !== CONTAINERS

Docker, inc.

Docker is a company that provides software (also called Docker) that allows you to build, run and manage software containers

COREOS

[troll_mode_on]CoreOS is dead, long live CoreOS![troll_mode_off]
Light weight and secure alternative to Docker

LXC/LXD

Low-level Linux container runtime

CRI-O

Implements OCI (Open Container Initiative) and based on runc or Clear Containers runtimes

more details on wat?! containers are?

  • Gianluca Arbezzano (@gianarb)
    Docker: The fundamentals
  • Giulio De Donato (@liuggio)
    Isoliamo un Processo senza Container

GETTING STARTED

$: DOCKER RUN HELLO-WORLD

image

Made of a set of layers,
like a Class.

CONTAINER

A process based on an Image,
like an Instance.


    namespace PhpUserGroup\Turin;

    use Docker\Contracts;
    use PhpUserGroup\MeetUp;

    class DockerMeetUp extends MeetUp
    {
        public static function build(): IImage;
    }


 


    use \PhpUserGroup\Turin\DockerMeetUp;


    $meetUp = new DockerMeetUp();

    $anotherMeetUp = new DockerMeetUp();

    $soOnMeetUp = new DockerMeetUp();


HOW BUILD imageS?

Using Dockerfile: `docker build . - t <USERNAME>/<APP>:<VERSION>`

    FROM prometherion/php7-nginx:1.1.3 

    #

    # Installing PHP needed extensions

    #

    USER root

    RUN apt-get update && apt-get install -y \

            sqlite3 \

            libsqlite3-dev \

        && docker-php-ext-install \

            bcmath \

            pdo_mysql \

            pdo_sqlite \

        && pecl install -o -f redis \

            &&  rm -rf /tmp/pear \

            &&  cat > /usr/local/etc/php/conf.d/redis.ini < EOF
          extension=redis.so \
            EOF \

        && composer global require hirak/prestissimo

    #

    # Application deployment

    #

    COPY . ./

 

OK, BUT...

WHAT THE HECK ARE LAYERS?!

  • FROM
  • ARG
  • FROM
  • RUN
  • CMD
  • LABEL
  • EXPOSE
  • ENV
  • ADD
  • COPY
  • ENTRYPOINT
  • VOLUME

  • USER
  • WORKDIR
  • ARG
  • ONBUILD
  • STOPSIGNAL
  • HEALTHCHECK
  • SHELL

HOW START A CONTAINER?


    docker run prometherion/php7-nginx:1.1.3   
 

HOW list All CONTAINERs?


    docker container ps
 

HOW VIEW LOGS?


    docker logs <CONTAINER_ID|CONTAINER_NAME>
 

HOW DETACH A CONTAINER?


    docker run -d prometherion/php7-nginx:1.1.3
 

HOW PUBLISH A PORT?


    docker run -d -p 8080:8080 prometherion/php7-nginx:1.1.3

HOW MOUNT MY FILES?


    docker run \

        -d -p 8080:8080 -v `pwd`:/var/www \

    prometherion/php7-nginx:1.1.3

 

HOW USE ENVIRONMENT VARS?


    docker run -e FOO=BAR prometherion/php7-nginx:1.1.3
 

HOW STOP A container?


    docker container stop <CONTAINER_ID|CONTAINER_NAME>

HOW REMOVE A CONTAINER?


    docker container rm <CONTAINER_ID|CONTAINER_NAME>

SO... are we ready for production?

DOCKER COMPOSE

tool for defining and running multi-container Docker applications.

AVAILABLE COMMANDS

  • up
  • down
  • build
  • run
  • logs
  • scale
  • push

DEMO TIME!

Questions...?

Docker 101 for Developers

By Dario Tranchitella

Docker 101 for Developers

Incontro PUG Torino: 22 Febbraio 2018

  • 317
Loading comments...

More from Dario Tranchitella