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

LaraconEU 2018 - Kickass Development Environmen...

LaraconEU 2018 - Kickass Development Environments with Docker

David McKay

August 30, 2018
Tweet

More Decks by David McKay

Other Decks in Technology

Transcript

  1. @rawkode @[email protected] Organiser of Things ◍ Cloud Native Glasgow ◍

    DevOps Glasgow ◍ MongoDB Glasgow ◍ PairProg Glasgow Software & Site Reliability ◍ Elixir / Rust / Go / Pony ◍ Docker / CI / CD ◍ DevOps / SaltStack ◍ Event-Driven Systems ◍ CQRS / ES
  2. My Development Environment Circa 2000 $ tree awesome-million-pound-project └── src

    ├── game.php ├── game.php.bk-david ├── game.php.bk-deano ├── main.php ├── main.php.maybe-fixed ├── main.php.bk-1999-12-02 ├── main.php.bk-1999-12-02.2 ├── player.php ├── player.php.orig └── .swp.player.php
  3. My Development Production Environment Circa 2000 $ tree awesome-million-pound-project └──

    src ├── game.php ├── game.php.bk-david ├── game.php.bk-deano ├── main.php ├── main.php.maybe-fixed ├── main.php.bk-1999-12-02 ├── main.php.bk-1999-12-02.2 ├── player.php ├── player.php.orig └── .swp.player.php
  4. “ Docker allows you to package an application with all

    of its dependencies into a standardized unit for software development.
  5. Docker ◍ Image Builder ◍ Image Delivery ◍ Virtualisation ◍

    Orchestration (Dev) ➢ docker image build ➢ docker image push/ll ➢ docker container run ➢ docker-compose Build. Ship. Run.
  6. (Simplified) Dockerfile for PHP FROM ubuntu:18.04 RUN apt install -y

    php-cli COPY hello.php /code WORKDIR /code ENTRYPOINT [“php”] CMD [“-v”]
  7. (Simplified) Dockerfile for PHP FROM ubuntu:18.04 RUN apt install -y

    php-cli COPY hello.php /code WORKDIR /code ENTRYPOINT [“php”] CMD [“-v”]
  8. (Simplified) Dockerfile for PHP FROM ubuntu:18.04 RUN apt install -y

    php-cli COPY hello.php /code WORKDIR /code ENTRYPOINT [“php”] CMD [“-v”]
  9. (Simplified) Dockerfile for PHP FROM ubuntu:18.04 RUN apt install -y

    php-cli COPY hello.php /code WORKDIR /code # PLEASE DON’T DO RUN cd /code
  10. (Simplified) Dockerfile for PHP FROM ubuntu:18.04 RUN apt install -y

    php-cli COPY hello.php /code WORKDIR /code ENTRYPOINT [“php”] CMD [“-v”]
  11. ENTRYPOINT and CMD Explained in 17 seconds ... CMD [“echo”,

    “Hello”] in a Dockerfile docker run my-image == $ Hello
  12. ENTRYPOINT and CMD Explained in 13 seconds ... CMD [“echo”,

    “Hello”] in a Dockerfile docker run my-image echo Goodbye == $ Goodbye
  13. ENTRYPOINT and CMD Explained in 10 seconds ... ENTRYPOINT [“echo”]

    CMD [“Hello”] in a Dockerfile docker run my-image == $ Hello
  14. ENTRYPOINT and CMD Explained in 7 seconds ... ENTRYPOINT [“echo”]

    CMD [“Hello”] in a Dockerfile docker run --entrypoint=”echo” my-image Woop! == $ Woop!
  15. ENTRYPOINT and CMD Explained in 4 seconds ... ENTRYPOINT [“echo”]

    CMD [“Hello”] in a Dockerfile docker run --entrypoint=”echo” my-image == $
  16. Docker ◍ Image Builder ◍ Image Delivery ◍ Virtualisation ◍

    Orchestration (Dev) ➔ docker image build ➔ docker image push/ll ➔ docker container run ➔ docker-compose
  17. Docker ◍ Image Builder ◍ Image Delivery ◍ Virtualisation ◍

    Orchestration (Dev) ➔ docker build ➔ docker push / pull ➔ docker run ➔ docker-compose
  18. Docker for Local Development 4 Easy Steps. I’ll discuss 3.

    1. Satisfy Dependencies 2. Introduce Docker for CI 3. Adopt Docker Shell Pattern 4. 12-Factor (Catch Alex’s talk on YouTube)
  19. docker-compose.yml version: “2.4” services: php: image: php:7 ports: - 80:80

    volumes: - .:/code:cached tmpfs: - /code/var/logs - /code/var/cache
  20. docker-compose.yml version: “2.4” services: php: image: php:7 … database: image:

    mariadb:10.1 environment: MYSQL_USERNAME: rawkode MYSQL_PASSWORD: *******
  21. docker-compose.yml version: “2.4” services: php: image: php:7 healthcheck: test: nc

    -z localhost 80 depends_on: database: condition: service_healthy
  22. Docker for CI ◍ Multi-Stage Builds ◍ Mind Your Build-Cache

    ◍ Be Wary of “Helper” Scripts ◍ We’ll cover these in the demo
  23. Docker Shell Pattern ◍ Your base container has all your

    system dependencies (Don’t use --ignore-platform-reqs) ◍ Work natively, but in the container ◍ You’ll still get all the perks
  24. Docker ◍ Image Builder ◍ Virtualisation ◍ Image Delivery ◍

    Orchestration (Dev) ➔ docker build ➔ docker run ➔ docker push / pull ➔ docker-compose
  25. Tips: Mindful of Network Collisions Every new docker-compose file is,

    potentially, a new docker network / bridge on your host. Eventually, you’ll get a collision docker-compose down Add -v to remove volumes
  26. Tips: Alpine Linux Unless you need Ubuntu / Fedora, use

    Alpine Linux Ubuntu -- 130MB / 85MB Alpine -- 3.99MB