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

Tech Talks 1: Docker

Tech Talks 1: Docker

Perkenalan fitur docker
Perbandingan dengan sistem lain
Tutorial docker sederhana
Dockerfile

Avatar for Fikih Firmansyah

Fikih Firmansyah

January 20, 2024
Tweet

More Decks by Fikih Firmansyah

Other Decks in Technology

Transcript

  1. Introduction • Backend Engineer at Xtend Indonesia • CTO of

    TestMate • Member of Indonesian Bioinformatics and Biodiversity Society • Google Developer Groups Medan • Open source enthusiast and Communities Fellow • Tech Background: Backend stuff, IaaS & PaaS Cloud, DevOps, more at https://fikihfirmansyah.my.id
  2. Apa yang akan dibahas - Perkenalan fitur docker - Perbandingan

    dengan sistem lain - Tutorial docker sederhana - Dockerfile
  3. Apa yang tidak akan dibahas - Memanfaatkan docker di real-life

    - Implementasi infrastruktur docker - Implementasi teknis lanjut
  4. Fitur - images • Ngebungkus setiap aplikasi dalam “kotak” yang

    sama (dependencies dan bisa dijalankan di mana saja) • Mengisolasi berbagai hal dari satu sama lain • Prosedur pembuatan yang terstandarisasi (Dockerfile)
  5. Fitur - containers • Mengelola kontainer ◦ Menjalankan & menghentikan

    ◦ Menyimpan & memuat (dari file) • Memasang volume ◦ Sharing data ◦ Persistensi data • Membuat Jaringan yang menghubungkan antar containers
  6. Fitur - workflow • Docker daemon dan CLI • Docker

    hub dan registry • Image versioning (pull, commit, pull, layers)
  7. Pull it! $ docker pull busybox • Search docker registry

    for repository of given name • Downloads the repository • Pulls only changes
  8. Pull it! $ docker pull busybox • Search docker registry

    for repository of given name • Downloads the repository • Pulls only changes next time
  9. Pull it! $ docker pull busybox • Search docker registry

    for repository of given name • Downloads the repository • Pulls only changes next time
  10. Run it! $ docker run busybox:ubuntu- 14.04 echo "hello" •

    Make sure that image is available (downloads if not found) • Create a container • Run a command
  11. Run it! $ docker run -it busybox:ubuntu- 14.04 sh •

    -it → makes container interactive • Create a container • Give you a shell access
  12. More complicated example • Run laravel project in a container

    • Run it as a daemon • • Bind it to network Make storage persistent
  13. Run it! $ docker run -d -v /var/docker/redis:/da ta -p

    6379:6379 --name=redis dockerfile/redis • -d → launch as daemon • -v /var/docker/redis:/data → mount directories • -p 6379:6379 → forward ports
  14. Run it! $ docker run -d -v /var/docker/redis:/da ta -p

    6379:6379 --name=redis dockerfile/redis • -d → launch as daemon • -v /var/docker/redis:/data → mount directories • -p 6379:6379 → forward ports
  15. Run it! $ docker run -d -v /var/docker/redis:/da ta -p

    6379:6379 --name=redis dockerfile/redis • -d → launch as daemon • -v /var/docker/redis:/data → mount directories • -p 6379:6379 → forward ports
  16. Watch it! $ docker ps -a Prints out information about

    all docker containers: • Running • Exited
  17. Watch it! $ docker logs -t --follow romantic_enstein • Get

    logs from stdin/stdout of container • -t → show timestamp • --follow → similar to tail -f
  18. Watch it! $ docker inspect romantic_enstein • Get info about

    container • Environment variables • Ports Links
  19. Tidy up docker rm <container_id> docker rmi <image_id> • Docker

    images use lots of space • Docker images can clog all your available space on server (no more pulling from registry)
  20. What we learned so far • Repository workflow ◦ Pull

    ◦ Commit ◦ Push • Tidying up after containers ◦ Rm ◦ Rmi • Monitoring ◦ Ps ◦ Logs ◦ Inspect ◦ Top • Running containers ◦ Interactive ◦ Daemon ◦ Mounting ◦ Forwarding
  21. DOCKERFILE # Use the official Node.js 14 image as a

    base FROM node:14 # Set the working directory in the container WORKDIR /usr/src/app # Copy package.json and package-lock.json (if available) to the working directory COPY package*.json ./ # Install app dependencies RUN npm install # Bundle app source inside the Docker image COPY . . # Expose port 3000 to the outside once the container has launched EXPOSE 3000 # Define the command to run the app CMD ["node", "index.js"]