Using Docker Multi-Stage Builds

Поділитися
Вставка
  • Опубліковано 5 лют 2025

КОМЕНТАРІ • 60

  • @zerobog
    @zerobog Рік тому +7

    I don't usually subscribe after one video, but this was straight to the point, with real life example which is very useful.

  • @polatalemdar9865
    @polatalemdar9865 2 роки тому +1

    I m watching from Turkey. Thank you boss

  • @chongerwin
    @chongerwin Рік тому +1

    Thanks!

  • @MuthaNagavamsi
    @MuthaNagavamsi Рік тому

    Checking UA-cam and found this video.
    By far one of the best videos I found around the topic multi-stage docker builds.
    @DevOpsToolkit thank you for keeping it simple and straight.

  • @namelessyoutubechannel
    @namelessyoutubechannel Рік тому +2

    What a brilliant tutorial! You are a great man sir. Keep up the good work.

  • @Peter1215
    @Peter1215 3 роки тому +4

    Thank you Viktor, always great to refresh on the fundamentals. I've had to explain multistage builds to developers recently, your vid would have been of great help, bookmarked for later :)

  • @1234mytubeuser1234
    @1234mytubeuser1234 Рік тому +1

    Sweet ,simple and to the point video. Subscribed!

  • @naresing
    @naresing 3 роки тому +2

    Great video as usual. Thanks Viktor

  • @vimalneha
    @vimalneha 3 роки тому +1

    Thanks Viktor, for a good reminder on Docker. Always great videos.

  • @abdallahnagy1
    @abdallahnagy1 11 місяців тому +1

    amazing minimal illustration

  • @chrisre2751
    @chrisre2751 3 роки тому +4

    Thank Viktor. I use multi-stage builds for long time.
    A video in the future about kubernetes operators (maybe vs helm) will be great.

    • @DevOpsToolkit
      @DevOpsToolkit  3 роки тому +2

      Adding operators to my TODO list... :)

  • @gauravverma3165
    @gauravverma3165 2 роки тому +1

    Excellent video. Thanks for sharing.

  • @jikol9631
    @jikol9631 2 роки тому +2

    Great and simple explanation, what else could you ask for.

  • @talatmasood
    @talatmasood 2 роки тому +1

    Excellent explanation, thank you

  • @CarloNyte
    @CarloNyte 3 роки тому +1

    This was great thank you for the thorough explanation!

  • @paurushgargtube
    @paurushgargtube 2 роки тому +1

    Such a great explanation and so to the point. Thanks a lot.

  • @lastidea4925
    @lastidea4925 2 роки тому +1

    Excellent explanation thank you a lot Sir!

  • @timothypulliam2177
    @timothypulliam2177 3 роки тому +1

    Amazing video. Thank you for sharing

  • @syrus3k
    @syrus3k 3 роки тому

    Absolute gold this video is.

  • @mi2a4a81kLa
    @mi2a4a81kLa 11 місяців тому +1

    Great video! Thanks!

  •  3 роки тому +1

    Really good video, and channel in general. I wish I have found it earlier.

  • @aleksandrarestov7150
    @aleksandrarestov7150 3 роки тому +1

    We use multi-stage builds on Golang projects and for compiling JavaScript static content. But sometimes come node js developers with dependencies up to 1Gb that needed in runtime.

  • @dmitriinadein4733
    @dmitriinadein4733 Рік тому +1

    Спасибо что делишься своими знаниями!

  • @lolFJKify
    @lolFJKify 3 роки тому +1

    Amazing content! I have learned a lot with your videos

  • @williampolinchak
    @williampolinchak 2 роки тому +2

    Great example.

  • @mtik000
    @mtik000 3 роки тому +5

    I use multi-stage builds in a similar way for my Python apps. I like to use python:3-buster (~850MB) as the build image and then python:3-slim-buster (~115MB) as the final image. This allows things (e.g. cffi) to compile during the build w/o the bloat needed in the run.

  • @hamidja1537
    @hamidja1537 Рік тому +1

    Thanks for sharing

  • @RVRead
    @RVRead 8 місяців тому +1

    Thanks for the wonderful explanation. I have one question; there are multiple docker image optimization techniques and one of them is using multi-stage build. Can you suggest why should anyone use any other technique (choosing minimal base image, minimize layer size and count, cache image layers, etc) when they are using multistage which eventually reduce image size and layers ?

    • @DevOpsToolkit
      @DevOpsToolkit  8 місяців тому +1

      It does not matter what you do in all the stages but the last. Build binaries, run tests, etc. If possible, the last stage should be based on scretch image. If that's not an option, use chainguard, alpine, or busybox as the base image of the last stage. Inside that stage, add only things that are needed (e.g. the binary) abd nothing else.
      As for your question... Multi stage builds are not really about optimization. The final stage is the image and those before it are just a convenient way to do something inside docker as opposed doing it outside. If, for example, you compile the binary outside docker and just add it to the image the end result will be the same.

    • @RVRead
      @RVRead 8 місяців тому +1

      @@DevOpsToolkit Thanks for taking time to answer. You are a gem.
      Just one thought again on same point - would you prefer to run the optimization (as mentioned above) in previous layers or developers should choose bulky image to finish the work and then always use lighter image for the final stage.

    • @DevOpsToolkit
      @DevOpsToolkit  8 місяців тому +1

      @RVRead I think that the two options you described are the same (or I misunderstood). You can use any image of any size in previous layers, assuming that by previous layers you mean previous stages. As long as the last stage is based on no image or a very small image you should be fine. What happens before the last stage is not that important.

    • @RVRead
      @RVRead 8 місяців тому +1

      @@DevOpsToolkit Thanks again for your expert opinion and kind response. Yes I was pointing to previous layers and now its clear to me :)

  • @sanketjaiswal1137
    @sanketjaiswal1137 3 роки тому +1

    Great video Viktor 👍 could you please make video on kubernete operators.

  • @DevOpsToolkit
    @DevOpsToolkit  3 роки тому

    Are you using multi-stage builds or you prefer building, testing, etc. outside Dockerfile?

  • @misteryu6819
    @misteryu6819 3 роки тому +2

    Great video as always. Is there a way you can catch the Unit Test error and feedback to your CI system, where you can clearly tell the user the Unit Test failed? As not all developers are willing to dive into the Jenkins (or other CI tools) and look into the logs, would be nice if there's a way to clearly identify it as a "unit test" error.

  • @andreykaparulin9214
    @andreykaparulin9214 3 роки тому +1

    Thanks

  • @havefuntrading6263
    @havefuntrading6263 3 роки тому +1

    Thank you, very useful video! For languages that require runtime like Java would you have any suggestions on how to best split the the image build? Is there something better we can do other than building on an image with jdk and running on image with jre?

    • @DevOpsToolkit
      @DevOpsToolkit  3 роки тому +1

      I haven't been working with java for a while now so I cannot have a concrete answer. If you asked 5 years ago, I would say "use jre in the final image or create executable (fat jar)". However, I'm sure a lot has changed in the java world since then.
      As a general rule, the final image should have only what you need, and nothing else. It should be minimalistic. Whether that is jre or something else I cannot say.

  • @mohamedsamet4539
    @mohamedsamet4539 3 роки тому +1

    Thank you for the video.
    When using multi-stage build we don't rely on application artifacts and artifacts registry (jar and nexus). Is it a good solution to have only docker images as "artifacts"?

    • @DevOpsToolkit
      @DevOpsToolkit  3 роки тому +1

      That depends. If you are building a CLI or a desktop app, or a library artifacts/releases need to be binaries. For everything else (apps running in clusters), I do not see a good reason for anything but images. That's all you really need. Those images contain the artifacts inside them.

  • @CarloNyte
    @CarloNyte 3 роки тому +3

    I've been testing for the past couple hours and kept running into the issue where alpine would not execute the go binary that was created. The solution was to use **FROM debian** instead of *FROM alpine*. Just a heads up for anyone else that runs into this problem. "This is because golang is not alpine base but debian base."

  • @usama57926
    @usama57926 2 роки тому +1

    Can we use multiple base images in one image?

    • @DevOpsToolkit
      @DevOpsToolkit  2 роки тому

      We can not. An image can have only one base image.

  • @TankaNafaka
    @TankaNafaka 3 роки тому +1

    Spending time with multi-stage dockerfiles sure can be fun, but I think it can be really tedious and really error prone work, especially if you have to deal with project where multiple programming languages are involved. Instead of guessing which base image to use, and what steps to choose, you already are spending precious hours just to get stuff nearly up and running. This is why I like the idea behind Cloud Native Buildpacks project. What do you think about it Viktor? BR, -Admir

    • @DevOpsToolkit
      @DevOpsToolkit  3 роки тому +1

      CNB is great. My only complaint is that it is in ruby.

    • @andreykaliazin4852
      @andreykaliazin4852 3 роки тому +1

      Ah, yes, this is another request coming up! If you are not too averse to Ruby (why, btw?) - could you please review CNBs in comparison with the multi stage docker builds? And use some example in Python with lots of dependencies! :-)
      (perhaps requiring C/C++ compilation - for example using cppyy framework at cppyy.readthedocs.io, if its not too much to ask)

    • @DevOpsToolkit
      @DevOpsToolkit  3 роки тому

      I haven't worked with python for a while. Can you create a sample app I could use?

    • @TankaNafaka
      @TankaNafaka 3 роки тому +1

      @@DevOpsToolkit depends what app you are after.? Hint you can also find on github topic python or flask, fastapi, for web 😃

    • @DevOpsToolkit
      @DevOpsToolkit  3 роки тому

      @@TankaNafaka I'll give it a try :)

  • @Yrez1234
    @Yrez1234 3 роки тому +2

    Hi Viktor, multi-stage builds are an awesome feature! However, I struggle when it comes to import unit tests / code coverage results, into the CI/CD tool. Generally, an XML JUnit file is generated when tests are executed, and this file can be uploaded using a built-in task from the CI/CD tool. However, this task cannot be used from the Dockerfile, so currently, the only workaround I found is to run the tests independently in the pipeline and import results outside the Dockerfile. Another way could be to copy the report file from the container to the agent running the pipeline, but as we use multi-stage builds, the stage where tests are executed is deleted once the final image is built. Do you have any suggestion to solve this kind of problem?

    • @DevOpsToolkit
      @DevOpsToolkit  3 роки тому +3

      If you need artifacts store in pipeline tools, multi stage is not a good option. That being said, I do not think that any type of artifacts should be stored in pipeline tools. They should be in registries or repositories. For convenience, pipelines might need to show those artifacts, but not to store them. Even in the case of visibility-only type of usage of those artifacts/results, pull request tends to be a much better place.

  • @renaulth2009
    @renaulth2009 2 роки тому +1

    Ah so the Dockerfile is almost like a Makefile in a sense

  • @90hijacked
    @90hijacked Рік тому +1

    too bad you didn't mention that the --target flag,
    you can define dozens of images in the dockerfile with arbitrary requirement chains yet build a single image and only its requisite stages. lazy evaluation for the win

  • @user-bv6il2nk4t
    @user-bv6il2nk4t 3 роки тому

    SIR PLEASE MAKE VEDIOS THESE
    ================K8 realtime Q========================interview questions varous source---mny source friend company helpall-----------------------------------------
    Most important Kubernetes 7-8 topics as per recent competition and live interview , these questions asking regular/product service based
    concept istio , what is service mesh very imp , ingress controller nginx why v imp? fluend for logs , prometheus grafan how intall monitor k8 , helm why? how?, gitops flow explanation using argo operator vimp .( helm and prome.. in all projects 100 prcnt questions ), opemshift adavmatage?
    concept of role based access security , service accounts very imp , meaning of manifest. meaning of policy in K8 , pod lifecycle what stages like pending how check stages? how createing aws cluster? tell AKS azure Eks aws infra setup what advantage tomorow docker engine support gone? explain in detail db flow --how setup master how many master how many slaves tell process of setup master salves for db . how u taking incremental backup database say perfona tool and how normal db backup example data at transit or rest S3? backuprestore frequency? startegy deploy canary bluegreen warmstandy?, secuirty service /frameork project asked atleast 30 min asked secuirty any public cloud ? what canary ,blue green, stdby , rollback restor? explain in detail helm , (full dns process load balmcer controller what happen i enter cnn.com all steps )? dev says api not work what u do? tell full process how integrate prometheus grafana if prometehus fail u use ELK ,log infra atlest? tell top 15 metrics in detail observe prmotheus as action will be based on that . how you decide autosaclig let me know common metrics tehse serevrs u need in big infra? hw many volumes and how mny port mapped ?explain in general in detail port forwarding ? what is sql proxy explain schema why we use? create bastion host reltime db secure create showme? rverse proxy implementation details? when proxy when reverse proxy difference? how you implement bastion host and port forward it?
    =====================================================================================================================================================
    Terraform realtime concept asking-
    State file , global S3 state local state , taint untaint , import ,(how sync manual machine by mistake creation and the current state), using cache terraform fast process. updt state terraform manual cretedresource, how we read other developer state file with your statefile using what terraform command, Json basics, ARM ofazure wahts difference ? why provisoner in terraform ? whats refresh and state pull whats difference? whats import? what target reffred terrafrm? whats self parameter ?can u get automatically all ips proviioned private public , then whats parameter terraform used? state pull ,refresh? syantax env variable Terraform? why workspace if module?
    =================================================================================================================================================
    HELPS ALL
    linux screenshare question interview zoom>product based-- whats dev/console , dev/null , logger command , logrotate.d , &1 ? !! &&? yum options , sometime rpm we need only rpm how then? suoders file? for many path permission singleuser how ALIAS command? setfacl why? stickybits why when u have chmod? what selinux concept? awk sed find 3 tell 5-10 wys in ur devops ? curl command how u use differnt way docker alo aws also? tee forlogs? exec >> ? netstat tulp? teacroute telnet?nmcli--ip assign?suppose vm with you now home you dont have company access so no net but u need wifi?> /dev/null 2>&1? exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1? curl what options u know?what meaning of epel? whats port why ip combined with port why? port is there why service? what ephemral port ? NACL why u need entry 32000 62500 even u have 443 entry at target? whats application port and wahts server ports ranges whats differece? why you need router and route table ? whats destination and target explain route table?
    asked sharing screen , sar ,log see using tail , boot problem grub , lvm asked details hw u use nfs server ? find tell 10 differnt way ? awk tell 8-10 ways in devops
    whats cidr whats blocksize basic network , not host but subnet range decide what factor? port? ipv4? forward port forwardip commands ,proxy,why proxy 2types proxy?
    ================================================================================================================================================================
    cloud===========
    Any publiccloud common q told .any cloud he told comfortable ---- flow 1 --only dedicated db flow explian --how youcreate bastion--master -slave count -- whats sql proxy for read write , tell basic schema manage devops side---backup sure asking--2 backups incremental [entire backuprestre DR db side] depth, normal asking script an d frequency how take ? security structure of your project in details --30 min mimimum asking service / existing project secuirty architecture. , how u do port forwrd i[ forward bastion? how ip /port/proxy all these asked, sql proxy--atleast basics schema maanged devops side? stateless lab , stateful db lab? entire process Site 2 site told spend some 200-300 rs practise it , aorganization yes like 20 account managing , Active directory- backend--SSO frontend flow lab tell , when NAT when IGW in route? if not NAT whats other flow same requirement? detailed q endppoints ? private endpoint , serverless as he told saves cost so becomes important. on premise jenkins ---aws side flow knowledge .DR , security ,project archtecture asking mainly, boto os atlest 2 module u know? python exprtise atlest basics? why you come here just doing institute labs? how many types VPC connection are there? you never did onpremise --aws coonection?whats VPN you nver configured for ur peers?please configure bastion host here. write servrelss function which undo a secuirty group change by a invader/hacker , in the time i send mail my security gone. whats ingress controler explain properly , DNS flow all steps properly ? whats use case of internal lB and App Lb , internal LB u used sql proxy or db flow? whats messaging queue itso crtical workflow , atleast learn basics API message queue , what happens dev comes API not works what steps? wht is L in doc of S3 why u need versioning? whats cross functional replication with version say you are hacked 100 %now? how u take backup master(database) in 2 availabilty zones right DR tell implemnation? API Flowlogs , lambda , Message queu , SNS pls learn told. complete workflow target maillist group on monitor error 100 % CPU consumed, ELK prome EKS explore workspaces its ok u not do.

  • @denischikita
    @denischikita Рік тому +1

    Why on an earth you'll need to do this with docker?