Docker (for developers)

Docker (for developers)

Some cool things about docker and docker-compose for a development environment. Talk at Auckland Node.js Meetup

63d1307df6bdc998ddc84bf0390c0ff7?s=128

Dmitry Rocha

May 31, 2018
Tweet

Transcript

  1. Dmitry Rocha dev - qotient Docker(for devs)

  2. We’ve updated our Privacy Policy

  3. % whoami Dmitry Rocha @dmitryrck

  4. Dev - Qotient

  5. None
  6. Qotient.com

  7. None
  8. None
  9. Docker!

  10. No, not yet

  11. None
  12. OMG, spoilers! https://dmitryrck.com/docker- nodejs/

  13. https://dmitryrck.com/docker-nodejs/

  14. “ Docker is a computer program that performs operating-system-level virtualization

    also known as containerization. It is developed by Docker, Inc. Docker is primarily developed for Linux, where it uses the resource isolation features of the Linux kernel such as cgroups and kernel namespaces, and a union-capable file system such as OverlayFS and others to allow independent ”containers” to run within a single Linux instance, avoiding the overhead of starting and maintaining virtual machines (VMs) ” ([Docker (software)Docker (software), Docker])
  15. None
  16. 1.85KB 1 $ docker run --rm hello-world 2 3 Hello

    from Docker! 4 This message shows that your installation appears to be working correctly. 5 6 To generate this message, Docker took the following steps: 7 1. The Docker client contacted the Docker daemon. 8 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 9 (amd64) 10 3. The Docker daemon created a new container from that image which runs the 11 executable that produces the output you are currently reading. 12 4. The Docker daemon streamed that output to the Docker client, which sent it 13 to your terminal. 14 15 To try something more ambitious, you can run an Ubuntu container with: 16 $ docker run -it ubuntu bash 17 18 Share images, automate workflows, and more with a free Docker ID: 19 https://hub.docker.com/ 20 21 For more examples and ideas, visit: 22 https://docs.docker.com/engine/userguide/ 23 24 $ Listing 1: docker run --rm hello-world
  17. ±100MB 1 $ docker run --rm -it ubuntu bash 2

    root@8140206e64bc:/# exit 3 $ Listing 2: docker run --rm -it ubuntu bash
  18. 1 $ docker run -it ubuntu bash 2 root@919fe536b5c7:/# mkdir

    /testing 3 root@919fe536b5c7:/# ls -ld /testing 4 drwxr-xr-x 2 root root 4096 May 29 09:04 /testing 5 root@919fe536b5c7:/# exit 6 exit 7 $ docker run -it ubuntu bash 8 root@f78f3e0f874c:/# ls -ld /testing 9 ls: cannot access '/testing': No such file or directory 10 root@f78f3e0f874c:/# Listing 3: docker run -it ubuntu bash
  19. Installing nodejs

  20. 1 $ docker run --rm -it ubuntu bash 2 root@0f98b2643c36:/#

    wget "https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar. → 3 bash: wget: command not found 4 root@0f98b2643c36:/# apt-get install wget 5 Reading package lists... Done 6 Building dependency tree 7 Reading state information... Done 8 E: Unable to locate package wget 9 root@0f98b2643c36:/# apt-get update 10 ……… 11 Get:17 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [1660 B] → 12 Fetched 25.2 MB in 12s (2070 kB/s) 13 Reading package lists... Done 14 root@0f98b2643c36:/# apt-get install -y wget 15 ……… 16 Done Listing 4: Install wget first :/
  21. 1 root@0f98b2643c36:/# wget "https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar.xz" 2 --2018-05-29 09:51:32-- https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar.xz 3 Resolving

    nodejs.org (nodejs.org)... 104.20.22.46, 104.20.23.46, 2400:cb00:2048:1::6814:162e, ... 4 Connecting to nodejs.org (nodejs.org)|104.20.22.46|:443... connected. 5 HTTP request sent, awaiting response... 200 OK 6 Length: 11349944 (11M) [application/x-xz] 7 Saving to: 'node-v8.11.2-linux-x64.tar.xz' 8 9 node-v8.11.2-linux-x64.tar.x 100%[=============================================>] 10.82M 502KB/s in 14s → 10 11 2018-05-29 09:51:47 (778 KB/s) - 'node-v8.11.2-linux-x64.tar.xz' saved [11349944/11349944] Listing 5: Download node
  22. 1 root@0f98b2643c36:/# tar xf node-v8.11.2-linux-x64.tar.xz 2 tar (child): xz: Cannot

    exec: No such file or directory 3 tar (child): Error is not recoverable: exiting now 4 tar: Child returned status 2 5 tar: Error is not recoverable: exiting now 6 root@0f98b2643c36:/# apt-get install -y xz-utils 7 ……… 8 Done 9 root@0f98b2643c36:/# Listing 6: Extract… ops, no extractor?
  23. 1 root@0f98b2643c36:/# tar xf node-v8.11.2-linux-x64.tar.xz 2 root@0f98b2643c36:/# /node-v8.11.2-linux-x64/bin/node 3 >

    console.log("hello world") 4 hello world 5 undefined 6 > Listing 7: Can I?
  24. What can you (developer) do?

  25. 1 apt-get update 2 apt-get install -y wget 3 apt-get

    install -y xz-utils 4 tar xf node-v8.11.2-linux-x64.tar.xz 5 /node-v8.11.2-linux-x64/bin/node Listing 8: Everytime
  26. 1 from ubuntu 2 3 run apt-get update && \

    4 apt-get install -y wget && \ 5 apt-get install -y xz-utils && \ 6 wget "https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar. && \ → → 7 tar xf node-v8.11.2-linux-x64.tar.xz 8 9 run ln -s /node-v8.11.2-linux-x64/bin/npm /usr/local/bin/npm && \ → 10 ln -s /node-v8.11.2-linux-x64/bin/node /usr/local/bin/node → 11 12 run apt-get install -y postgresql-client Listing 9: Dockerfile
  27. How to use it?

  28. docker ▶ ‘docker run --rm hello-world’ ▶ ‘docker build -t

    mynode .’ ▶ ‘docker run --rm -it mynode bash’ ▶ ‘docker run --rm -it -v /home/dmitry/myproject:/app mynode bash’ ▶ ‘docker run --rm -it -v /home/dmitry/myproject:/app -w /app mynode bash’ ▶ ‘docker run --rm -it -v /home/dmitry/myproject:/app -w /app -v node_modules:/app/node_modules mynode bash’
  29. docker-compose ▶ ‘docker-compose pull’ ▶ ‘docker-compose build’ ▶ ‘docker-composer run

    --rm web bash’ ▶ ‘docker-composer run --rm web bash -c ”psql -h db -U postgres”’
  30. 1 version: "3.3" 2 3 services: 4 app: 5 build:

    6 context: . 7 volumes: 8 - .:/app 9 - node_modules:/app/node_modules 10 working_dir: /app 11 links: 12 - db 13 14 db: 15 image: postgres 16 17 volumes: 18 node_modules: Listing 10: docker-compose.yml
  31. from ubuntu run apt-get update && \ apt-get install -y

    wget xz-utils && \ wget "https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar. && \ → → tar xf node-v8.11.2-linux-x64.tar.xz -C /opt && \ ln -s /opt/node-v8.11.2-linux-x64/bin/npm /usr/local/bin/npm && \ → ln -s /opt/node-v8.11.2-linux-x64/bin/node /usr/local/bin/node && \ → apt-get install -y postgresql-client && \ rm /node-v8.11.2-linux-x64.tar.xz && \ rm -rf /var/lib/apt/lists/* Listing 11: Dockerfile optimized
  32. 1 $ du -sh /var/lib/docker/ 2 38G /var/lib/docker/ Listing 12:

    Disk usage (macOS)
  33. None
  34. Biography d ocker2018Docker(software).Docker(software). . [2018-05-15]https://en.wikipedia.org/w/index.php? title=Docker_(software)&oldid=839414224 Page Version ID: 839414224