32
MrJimmy
90d

Kinda ashamed to ask but... what the hell are containers (like docker)?
I mean, why not just installing the service directly on the machine? Or why not using a normal VM? And what is the difference between a container and a VM?

Comments
  • 32
    My best description is if you put your food on the bench, it will touch the entire bench.

    Put your food in a container and on the bench, it will just touch the container.

    So running apps in a container in theory can prevent malicious activity for example.
  • 1
    📌
  • 10
    An application inside a container is more portable. It contains the OS and anything else needed to make it run. This allows you to run it on your machine, aws, azure or your dad's and it will run the exact way.
  • 4
    @lxmcf great example, thanks. But again, why that and not a virtual machine? (@dan-pud)
  • 7
    Hmmm long story short there are two cases that i.m going to explain : using docker in dev env and prod env.
    So statting with dev for example having many projects some are running on mysql older or newer php 5 or php 7 some are running in java 7 others in java 8 postgresql etc i simply start a container with the required service and it.s just working don.t need to stay set the env for every project switching. Plus i can play with beta or newest tchnologies withput installing them on local.

    On production env the plus side of the doker is the scalability and availabily u can now scale horizontallly not just vertically (u can add more servers not just more ressources to a server) secondly there are technologies that are just fallowing containers and spin a new one or reset a container that is not responding anymore. I have a java backend that has many containers i can update some portions of the app with 0 downtine ...

    Hope i gave u some reasons why docker is cool :)

    Second
  • 2
    @MrJimmy it.s more light then a full os inside vm plus it.s easyer to deploy
  • 2
  • 2
    @MrJimmy Not 100% sure about this so don't quote me but VM is emulation of instructions where a container is an interpretation of instructions.

    So less performance degradation, access to all system hardware and information, kinda like a runtime i guess.
  • 1
  • 7
    Although most have been said:

    We had tge problem of: "it works on my machine" you had java 8.x.x, while the server had java 8.y.y installed and so on.

    The fix was to use either a dev server or a vm. Now dev server has the downside of non local development, whill vms have the downside of resources. You have hardware run an os, and an hypervisor run an os (per VM). Often this resulted in using one huge VM having apache, php, mysql, ... Installed and never really updated (instead of one vm per service which would be easier in updating these services).

    Now enter docker (or other container technologies, there's not just docker!). Instead of having an os, than a hypervisor and one (or multiple) vms runing on top of that you have your "vms" running directly inside your kernel. But completly isolated. You basically get an almost full vm, but without the hypervisor overhead.
  • 1
    2 words: Portability, Lightness
    1 line: ability to divide your application into microservices.
    And a duck 🐤
  • 5
    So an example that's been brought up a few times in these comments, but not addressed directly.

    Imagine you are shipping an app, and you want to make a simple unit of "this is everything you need, just run it and go" so you ship a VM. Everyone thinks this is a great idea and everyone starts shipping their apps as VMs the world is great but there's one problem:

    I'm running 18 Fucking kernels because every freaking vm has it's own kernels and libraries, most of which are the same damn version. Like fuck!

    Now imagine if all the VMs were able to recognize that your host machine has a kernel, and all the libraries, and only added what was special to them. What if every VM used the host kernel and libraries and you didn't have a host running a kernel for the sole purpose of running 18 other kernels.

    That's a container.
  • 1
    2/2 but wait, why even ship a VM in the first place?

    Well because everything you do to a system can cause some weird messup.

    This app works 100 percent of the time...well unless you tamper with this file that should never be touched...wait wtf...*2hrs later* oh! So strace reveals that nginx fucks with that file under unknown circumstances...sometimes?.... Huh. But we need nginx... Shit...

    It's nice for the app to always be run in a perfectly crafted and consistent environment for everyone always.

    Containers are like VMs without all the bloat, speed hits, and all the other problems of VMs.
  • 4
    Thanks a lot to everybody for the clear examples, and to @dan-pud and @Wack for the more tech insights. I finally get the point of containers, yayyy!!!
  • 4
    Vm is at least 1,5gb, container can take as small as 5mb. It also does not waste CPU/mem
  • 0
    okay long story short

    why use container ?

    cause we follow the trends

    kidding
  • 1
    I use it because it is lighter. I can put the entire server system online during code and offline after, with just one command.

    If I need other php version to other project, I just open its container. :)
  • 3
    Ever hear of chroot? A container is basically just a chroot with its own network devices and either nonexistent or horribly configured resource limits.
  • 2
    Docker containers can share the host OS kernel. It basically makes deployment easier and it's also easier to parallelize the services you're putting in these containers.
  • 2
    Simplest way I can put it:
    A VM emulates the hardware as well as the entire guest OS. A container does not.
Your Job Suck?
Get a Better Job
Add Comment