r/AskComputerScience • • Aug 14 '19

Docker

What problem does docker (and containers) solve? And in which projects should it (or not) be used?

Maybe an Eli5 because I made a long research and didn't get an answer yet.

37 Upvotes

17 comments sorted by

18

u/corpodop Aug 14 '19

The same type of problem that a virtual machine would solve, but you don't have to carry the whole operating system. in each docker image.

Hence a docker image can be very small, holding just what you need. It lead to faster boot/restart time.

It also allow docker images to be composed out of each other. Let say a docker images for a basic node.js, that you extends to build a image that run your application in production ( basic node + all your adhoc crap ), then you can extends that extension to have a docker image running your integration tests ( basic node + all your adhoc crap + testing framework and test code )

It's also a good way to ensure reproducibility and portability of a environnement. ( your dev env == prod, witch is pretty awesome )

Many use. think of it of a fancy VM on steroid. ( that you can share and re-use, like a library ).

And that the "dev" point of view, if you start thinking about Operations ( OPS ) and things like docker swarm and kubernete, it's a whole lot more of use and application.

It's also a neat tool all around.

7

u/worldDev Aug 14 '19

Also very convenient for consistent testing and building processes on CI runners with minimal work.

2

u/EquationTAKEN Aug 15 '19

Leeching onto the top comment to add:

One thing I also use it for is to not have to install a bunch of things on my machine. If I need to run a Python script, I spin up a container that runs it and shuts itself down. Ruby script, same thing.

5

u/011101000011101101 Aug 15 '19

Others have covered a lot of the benefits well, but there are some downsides. The main one i know of is when you need high performance storage. With the native way to mount storage into a running docker container, docker creates overlay storage. So basically you have a virtualized hard drive. I was working on deploying a service to AWS that works well with seqiential scan drives (HDDs), so we were using st1 storage from EBS. However once you have the docker overlay all the benefits you get from the st1 storage in this case are lost.

So basically anything that needs to be highly optimized could benefit from deploying via something like puppet or ansible instead of docker. Any data store is probably best to go without docker unless you're putting very little load on it.

5

u/seabrookmx Aug 15 '19

This is easily solved with a volume mount. The overlayfs is only used when you write to the main filesystem that is backed by the docker image.

It definitely adds to the complexity of the deployment, but I wouldn't immediately jump to "deploy with puppet or ansible" if you need fast storage.

We have a few projects that deploy their main databases as docker containers (in a Kubernetes cluster) and performance is exactly the same as it was on a vanilla EC2 instance or XenServer instance. Which is expected as our Kubernetes hosts are also backed by EC2.

1

u/011101000011101101 Aug 15 '19

Maybe our people that set it up fucked it up then. I didn't dig too deep into the docker setup in this instance, but i was running performance tests against one deployed with cloud formation + puppet and one deployed with docker and the performance took a major hit. However we switched the drives to gp2 and the performance went back up a bit. Still not as good, but good enough in this case.

3

u/[deleted] Aug 14 '19 edited Aug 14 '19

Build an app, put it in a container once, run anywhere.

You can run it on your computer, your friend’s computer, Amazon’s cloud computer, your grandma’s computer as long as you share that container it will run anywhere without error(well that’s the idea).

Container is light and portable so it takes seconds to run and doesn’t need to lug around Operating system therefore much less storage needed.

If you want to know why containers, lookup monolith vs microservices.

1

u/KernowRoger Aug 15 '19

First and foremost docker allows you to run your application consistently across many platforms. If it works for me it should (in theory) work anywhere that supports docker. Docker images can also be built from other ones. So when I'm building my aspnetcore rest API I can start with Microsoft's ApsNetCore 2.2 image and simply add my application. That image contains all the prereqs needed to run my site. So now I have a single image containing all prereqs that can be run anywhere. This can then be pushed to a repo and pulled anywhere. Then you can start using k8s. So combined with k8s I can easily have a cluster running across multiple servers with any number of images of my site running with load balancing. K8s will aim to keep X images running. So if one fails it kills it and starts another. We also use rancher which will automatically provision a new aws server if one goes down. Now we have multiple servers with automatic fall over recovery and multiple images spread across those servers with automatic recovery as well. It's also very easy to add auto scaling to the number of containers. This means short of aws going down the site is pretty bullet proof.

-2

u/HasFiveVowels Aug 15 '19

In my experience, unless you're handling a very heavy project, docker is overkill.

5

u/011101000011101101 Aug 15 '19

A lightweight microservice is perfect for docker. Also large docker images can be pretty slow to download to new hosts all the time. Can you provide more detail on why you have this opinion?

2

u/HasFiveVowels Aug 15 '19 edited Aug 15 '19

It seems everyone always eschews the benefits of docker without looking at the drawbacks. I have about 10 years of experience designing, building, and maintaining web applications, some that host hundreds of thousands of users and others that handle all sorts of high volume communications. My opinion of docker comes from my experience in this role. About 5 years ago, during the height of docker mania, I gave it a go on one of my projects. And I learned I gained basically nothing that wasn't already a trivial concern and what I lost was stuff like the ability to interact directly with the OS, its networking, etc. It seems everything has this additional layer of complexity. And... for what? Easier deployment? How many deployments are you doing, exactly? And, also, if you're working on a project like this I would guess you're using AWS or Google Cloud Services to host it and, if you are, just make a disk image of the install and deploy instances. Instances are basically docker containers already and come with a full API for managing them. Furthermore, why is it necessary for these applications to have this Java-y "write once, run anywhere" aspect? These are servers! You have full control over the environments! (edit: just realized that I take for granted that my computer is MacOS and I run on linux, so dev environments is never an issue for me) Managing environments is not such an overwhelming task that it needs a solution that involves this entire pseudo-VM to run your application in. If it is, then I would assume you're working on a "very heavy project" (as I alluded to in my previous comment). A lot of the things that docker solves are things that should be possible with a small script or that just aren't that big of a concern for projects of a moderate size. Just my two cents and I know others disagree but, IMHO, docker's not all it's cracked up to be.

1

u/011101000011101101 Aug 15 '19

I haven't gone through the process of creating aws amis so I don't know how easy or hard that is. However at my company they didnt want to give us access to create AMIs citing security concerns. So our options are ec2 with puppet, ansible, or something similar, or docker + ECS/EKS.

As for "how many deployments are you doing?".. to production, maybe a couple times a week. To non-production for testing or staging, as a team of 4 we probably deploy 20 or so times a week on average. It only takes a few minutes to test build and deploy, so we run the whole pipeline to make sure our branches are fully functional.

1

u/HasFiveVowels Aug 15 '19

By "how many deployments", I meant concurrent processes rather than code pushes. Unless your dependencies are tied strongly to the OS and frequently changing, there's no real need for that kind of encapsulation. It's naturally going to depend on the project but in my experience, an issue with dependency management is something that should be sorted out on the OS level, not a VM level.

All this said, docker isn't worthless and there are situations where it would be beneficial (e.g. in your situation where access to certain things is restricted due to security concerns). But I've seen it sold as this generalized solution to a general problem and, it seems to me, that unless you have a specific reason for using docker, you shouldn't be using it.

1

u/011101000011101101 Aug 16 '19

By "how many deployments", I meant concurrent processes rather than code pushes

Well my last project would have ~100 instances of the same service pointing at different databases. We'd build the code, docker image, and deploy to update all of them about a half hour. Is that what you meant or am i still not getting it?

1

u/HasFiveVowels Aug 16 '19

Yea, that's what I meant. That's a crazy number of instances, though. Couldn't you just do multi-tenancy and load balance those? Seems like you must have had a significant amount of waste. Or were all those databases read replicas? Why so many instances each with a dedicated DB?

1

u/011101000011101101 Aug 16 '19

Our production sql database cluster is around 100 separate servers just for the primaries. Then we have multiple backups on top of that, but we were connecting to the primaries. And the nature of the application needed independent services for each database instance.

...and all those servers really are necessary because peak cpu on the databases usually hit around 60% or so on a normal day. I think our service uses about 2500 cores in aws during peak traffic.

Keep in mind the databases are for much more than just the service I was working on.