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

Docker for Frontend Engineers

Docker for Frontend Engineers

In this (internal) workshop, I led a session to familiarize a group of frontend engineers with Docker.

This version of the workshop was held at Royal Schiphol Group in October 2017.

Kerim Satirli

October 30, 2017
Tweet

More Decks by Kerim Satirli

Other Decks in Programming

Transcript

  1. Docker History • 1974: Matijs born • 1979: Unix V7

    • 2001: Linux VServer • 2008: Linux Containers (LXC) • 2013: Docker ⚠ learn more: dcmnt.me/2hjIl5V
  2. What Docker is not • not good at running multiple

    processes • not suitable for all kinds of applications • not (very) good at distributed stateful applications
  3. Docker Images • Tarball of OS and application • built

    from a Dockerfile • can use Docker Compose, Packer, Ansible etc.
  4. FROM withmethod/alpine-base:3.6 RUN \ apk \ add \ --no-cache \

    nodejs=6.10.3-r1 \ nodejs-npm=6.10.3-r1
  5. FROM withmethod/alpine-base:3.6 ENV IMAGE_VERSION=6.10.3-r1 RUN \ apk \ add \

    --no-cache \ nodejs=${IMAGE_VERSION} \ nodejs-npm=${IMAGE_VERSION}
  6. FROM withmethod/alpine-nodejs:6.10.3-r1 ENV IMAGE_NAME=loop-and-crash ENV IMAGE_VERSION=1.4.3 ENV WORKDIR=/tmp WORKDIR "${WORKDIR}"

    ADD "https://github.com/withmethod/${IMAGE_NAME}/archive/${IMAGE_VERSION}.tar.gz" "${WORKDIR}" RUN \ tar xzf "${IMAGE_VERSION}.tar.gz" \ && \ rm -rf "${WORKDIR}/${IMAGE_VERSION}.tar.gz" WORKDIR "${WORKDIR}/${IMAGE_NAME}-${IMAGE_VERSION}" RUN npm install --production USER "alpine" EXPOSE 2774 CMD ["npm", "start"]
  7. FROM withmethod/alpine-nodejs:6.10.3-r1 ENV IMAGE_NAME=loop-and-crash ENV IMAGE_VERSION=1.4.3 ENV WORKDIR=/tmp WORKDIR "${WORKDIR}"

    ADD "https://github.com/withmethod/${IMAGE_NAME}/archive/${IMAGE_VERSION}.tar.gz" "${WORKDIR}" RUN \ tar xzf "${IMAGE_VERSION}.tar.gz" \ && \ rm -rf "${WORKDIR}/${IMAGE_VERSION}.tar.gz" WORKDIR "${WORKDIR}/${IMAGE_NAME}-${IMAGE_VERSION}" RUN npm install --production USER "alpine" EXPOSE 2774 CMD ["npm", "start"]
  8. FROM withmethod/alpine-nodejs:6.10.3-r1 ENV IMAGE_NAME=loop-and-crash ENV IMAGE_VERSION=1.4.3 ENV WORKDIR=/tmp WORKDIR "${WORKDIR}"

    ADD "https://github.com/withmethod/${IMAGE_NAME}/archive/${IMAGE_VERSION}.tar.gz" "${WORKDIR}" RUN \ tar xzf "${IMAGE_VERSION}.tar.gz" \ && \ rm -rf "${WORKDIR}/${IMAGE_VERSION}.tar.gz" WORKDIR "${WORKDIR}/${IMAGE_NAME}-${IMAGE_VERSION}" RUN npm install --production USER "alpine" EXPOSE 2774 CMD ["npm", "start"]
  9. FROM withmethod/alpine-nodejs:6.10.3-r1 ENV IMAGE_NAME=loop-and-crash ENV IMAGE_VERSION=1.4.3 ENV WORKDIR=/tmp WORKDIR "${WORKDIR}"

    ADD "https://github.com/withmethod/${IMAGE_NAME}/archive/${IMAGE_VERSION}.tar.gz" "${WORKDIR}" RUN \ tar xzf "${IMAGE_VERSION}.tar.gz" \ && \ rm -rf "${WORKDIR}/${IMAGE_VERSION}.tar.gz" WORKDIR "${WORKDIR}/${IMAGE_NAME}-${IMAGE_VERSION}" RUN npm install --production USER "alpine" EXPOSE 2774 CMD ["npm", "start"]
  10. FROM withmethod/alpine-nodejs:6.10.3-r1 ENV IMAGE_NAME=loop-and-crash ENV IMAGE_VERSION=1.4.3 ENV WORKDIR=/tmp WORKDIR "${WORKDIR}"

    ADD "https://github.com/withmethod/${IMAGE_NAME}/archive/${IMAGE_VERSION}.tar.gz" "${WORKDIR}" RUN \ tar xzf "${IMAGE_VERSION}.tar.gz" \ && \ rm -rf "${WORKDIR}/${IMAGE_VERSION}.tar.gz" WORKDIR "${WORKDIR}/${IMAGE_NAME}-${IMAGE_VERSION}" RUN npm install --production USER "alpine" EXPOSE 2774 CMD ["npm", "start"]
  11. FROM withmethod/alpine-nodejs:6.10.3-r1 ENV IMAGE_NAME=loop-and-crash ENV IMAGE_VERSION=1.4.3 ENV WORKDIR=/tmp WORKDIR "${WORKDIR}"

    ADD "https://github.com/withmethod/${IMAGE_NAME}/archive/${IMAGE_VERSION}.tar.gz" "${WORKDIR}" RUN \ tar xzf "${IMAGE_VERSION}.tar.gz" \ && \ rm -rf "${WORKDIR}/${IMAGE_VERSION}.tar.gz" WORKDIR "${WORKDIR}/${IMAGE_NAME}-${IMAGE_VERSION}" RUN npm install --production USER "alpine" EXPOSE 2774 CMD ["npm", "start"]
  12. Building Images • docker build . • docker build --file

    single-line.Dockerfile . ⚠ learn more: dcmnt.me/2zOHtNn
  13. Running Images • docker run $containerName $command • docker run

    alpine /bin/echo "Hello " ⚠ learn more: dcmnt.me/2zOdR2Q
  14. Running Images • docker run $containerName • docker run busybox

    echo "Hello " ⚠ learn more: dcmnt.me/2zOdR2Q
  15. Listing Images docker \ run \ --name portainer \ --privileged

    \ --detach \ -p 9000:9000 \ -v /var/run/docker.sock:/var/run/docker.sock \ -v ~/Sites/docker-data/portainer/:/data \ portainer/portainer \ --no-auth \ -H unix:///var/run/docker.sock ⚠ learn more: dcmnt.me/2zOdrtm
  16. Takeaways • Containers are not new but require different thinking

    • Docker Images work best when they are minimal • Do not overcomplicate your image's build instructions • Security is hard, so ask around for best-practices