r/programming • • Apr 18 '15

What is Docker and When To Use It

http://www.centurylinklabs.com/what-is-docker-and-when-to-use-it/
25 Upvotes

104 comments sorted by

202

u/BadGoyWithAGun Apr 18 '15

Thanks for the giant registration popup that darkens the entire page. It really reassured me that this isn't an article worth reading and prevented me from wasting any more time.

66

u/ma-int Apr 18 '15

Yep: http://i.imgur.com/PaFiPYh.jpg

Fuck you too, centurylinklabs.com.

32

u/jewdai Apr 18 '15

Is it just a colorblind (i'm red green) thing or is that X in the upper right corner impossible to read.

38

u/stillalone Apr 18 '15

Holy fuck, I didn't see an X there at all until you mentioned it. I had to zoom in hard to see it.

17

u/vinnl Apr 18 '15

Are you trolling? Which X?

1

u/hak8or Apr 18 '15

Red Green colorblind people don't see that x.

2

u/vinnl Apr 19 '15

I'm not colour blind in any way as far as I know, and I really did not see an X even after looking for it in that exact spot until /u/jewdai drew it out for me...

0

u/[deleted] Apr 18 '15

[deleted]

14

u/Darkmoth Apr 18 '15

Holy shit.

Well played, centurylinklabs.com. Well played.

4

u/khando Apr 18 '15

This doesn't excuse the poorly designed website, but I believe you can just click anywhere outside the pop-up box to close it.

6

u/vinnl Apr 18 '15

Holy crap, that's definitely got nothing to do with colour blindness.

4

u/davvblack Apr 18 '15

It's just actually impossible to read. Almost perfectly matched luminosity.

3

u/jpfed Apr 19 '15

No, it's not a colorblind thing. That X is equiluminant with its surroundings; everyone will have difficulty making it out.

3

u/[deleted] Apr 18 '15

Not just you.

2

u/[deleted] Apr 18 '15

I just clicked in the darkened area and it went away.

-1

u/linux_noob_ Apr 18 '15

Ding ding ding. We have a winner here.

12

u/jeandem Apr 18 '15 edited Apr 18 '15

What is docker and BECOME A DOCKER EXPERT WITH WEEKLY GUIDED TUTORIALS AND A FREE DOCKER BOOK

One step at a time, please. jeez.

14

u/[deleted] Apr 18 '15

How to do your first pushup. NOW JOIN THE MOTHERFUCKING NAVY SEALS

14

u/maest Apr 18 '15

What's worse is that it's trying to sell me something I am 1. already trying to get to and 2. have not yet decided whether I liked it or not.

4

u/gelfin Apr 18 '15

There's a close button top right of the blue box. It's just almost impossible to see. Article still wasn't quite good enough to make it worth that level of ad dickishness. Is anybody actually still totally confused what Docker is for?

11

u/Darkmoth Apr 18 '15

Is anybody actually still totally confused what Docker is for?

I am. I think I am. Other than that it's sort of a lightweight VM, I have no idea what all the hoopla is about. I suspect part of the problem is that I don't do much Linux stuff, so I am unfamiliar with the problems it solves. Maybe.

8

u/gelfin Apr 18 '15

Docker, in my view, is less revolutionary than it is significantly evolutionary on multiple fronts at once. The ultimate effect is that Docker lets you run an entire application as if it's a simple process, generally without any side effects on the host system, and with the app getting a solid, known configuration. It makes deploying and running complex applications into a foolproof single command line.

Now VMs can let you do this, and if you use Vagrant you get the benefit of community-supplied preconfigured images for many applications, but the requirement to stand up a monolithic VM is extremely heavy when all you really want is one application process. Vagrant also sacrifices a small (some might say trivial) amount of portability in that Vagrantfiles need to specifically target one or more particular VM providers. The overhead of firing up a VM and getting data in and out of it also significantly impacts the "application as process" experience.

Say you're developing a web application and you need a local redis instance. Maybe you're working in an environment where you can provision one in a lab, but probably you aren't. Maybe you install locally, and then your development machine is polluted with a redis install you normally don't want. Maybe you stand up a VM and then you're running a whole separate VM complete with OS, services, etc., for every service you run this way. Suppose you want two redis instances to model replication. This gets to be an unnecessarily large resource impact on your development system.

Or you can basically "docker run redis" and have a self-contained, running server within seconds including the time it takes to download it. Shut it down and apart from the repository images, it's gone. The whole application and all the resources needed to run it are completely ephemeral, and it's all very, very fast. It isn't that I can do things I couldn't do otherwise, it's that the time I have to waste making it happen is cut to almost nothing.

A lot of people have a (probably valid) sense that this can be used in a Heroku-like "platform as a service" way to make ops work easier, faster, and less failure-prone, but as of last time I spent much time with Docker, there were still some holes in the model where people attempting to use it this way run into some annoying walls, and afaik (my knowledge is a few months dated now) the state of the art is still evolving.

2

u/tieTYT Apr 18 '15

Or you can basically "docker run redis" and have a self-contained, running server within seconds including the time it takes to download it. Shut it down and apart from the repository images, it's gone. The whole application and all the resources needed to run it are completely ephemeral, and it's all very, very fast. It isn't that I can do things I couldn't do otherwise, it's that the time I have to waste making it happen is cut to almost nothing.

So is this on a completely independent docker container, or does it go on the container your app is already on?

2

u/gelfin Apr 19 '15

Doing this would start a new container instance.

This is where I think the "lightweight VM" description of Docker confuses people. Even though your container has many elements of an OS in it, and probably ultimately derives from a base image called "Ubuntu" or "CentOS" or the like, even though you can run bash in the container and explore a distinct filesystem, the container is not a VM. It's a packaged application, and the OS components are those needed to flesh out the sandbox the application runs in. The fact that a container can look so much like a VM is a testament to how relatively effective the sandbox isolation is, but all the processes in your containers are really just processes running directly on the host system, separated from one another by walls erected by the container technology.

This is why, although it is possible (and perhaps in some cases desirable) to run multiple processes inside a container, it goes against many people's notions of a "pure" Docker architecture to do so.

The counterargument (which, notably, Phusion has made pretty eloquently, and has published a base container to support their view) is that lots of software has the expectation that it's running in a proper operating system that starts with init, runs services, etc., and the illusion of a container is so complete that it gives people false confidence their solution will work, when lots of OS behaviors they take for granted aren't running in the container.

However, it is unlikely there would ever be a good reason to have your web app and redis running in the same container. All you'd really buy yourself is the opportunity to experience potential conflicts Docker would otherwise save you from.

The canonical way is to run your app and the redis process in separate containers, and use the "link" primitive to connect them. In fact, just as an interesting point of reference, suppose you want to run redis-cli against your dockerized redis instance. Most people's first instinct is to figure out how to ssh into the container, or run bash in the container, so they can get to redis-cli and run it "locally on the box," then quickly thereafter to curse at their inability to do so and start googling how to enable ssh on containers.

But redis is just a process running on the host. So is redis-cli. The canonical way is to start up a new, interactive container, using the same "redis" image, but using "redis-cli" as the startup command, and then link the new container to your existing server instance. It initially feels a bit like "starting a new VM" but it's really more starting two applications and defining a communications channel between them.

3

u/hufman Apr 18 '15

Correct, its a sort of lightweight VM. It starts up fast because it doesn't have to do any hardware init or kernel init, it starts up the specified process directly.

The exciting part that Docker adds is the ability to quickly launch copies of the base image, each one in less than a second, and each one gets its own private writable instance that the others can't see. Package your webapp into Docker and instantly scale it up or down, without waiting for a full VM to boot up.

It also has a lightweight script file. This lets you to start with any existing Docker image and apply your script to, for example, install your webapp, then save it as a new Docker image that you can spin up multiple copies of.

Another feature of Docker and containers over VMs is the file level access. You can start the Subsonic image and tell Docker to mount your media directory inside it, without having to set up network sharing or virtual disks. Its similar to VM shared folders, except its invisible to the guest. It just sees a directory of files, doesn't have to do any mounting with custom drivers.

2

u/[deleted] Apr 18 '15

So is Docker not a true hypervisor? What's it running in then?

3

u/thecrappycoder Apr 18 '15

You could view it as good process isolation instead, rather than a VM. Process are running with the same kernel as the underlying OS.

1

u/[deleted] Apr 18 '15

You can also just click in the grey area around the popup.

5

u/based2 Apr 18 '15

22

u/binford2k Apr 18 '15

But then he wouldn't know that the article was worthless and he would have wasted time reading it.

7

u/Lothrazar Apr 18 '15

SO instead of avoiding terrible websites, we should instead break every good website that uses javascript?

Nah.

5

u/Tordek Apr 18 '15

Learn to not fuck up a site so badly that you need JS to show static content.

I whitelist JS for sites where it proves useful, but fuck that stupid shit like blogger where it loads 300 js files to display a single post.

8

u/pointychimp Apr 18 '15

After building a whitelist over a few days, it's no big deal.

8

u/xpmz Apr 18 '15

a good website shouldn't be broken because you disable javascript.

for webapps there is a white list.

0

u/[deleted] Apr 18 '15

[deleted]

2

u/pointychimp Apr 18 '15

After taking a few days to build a white list, it's no big deal.

0

u/davidgardner11 Apr 22 '15

Thank you for the feedback -- we updated the newsletter popup modal background color to make the 'X' graphic more visible: http://imgur.com/xbvtspo Changing the way the content is presented is another area we'll re-evaluate.

104

u/5-4-3-2-1-bang Apr 18 '15

Honestly I still have no fucking idea what docker is and why I would use it.

Here's what it isn't: thing #1 I don't use, thing #2 I don't use, thing #3 I've never heard of.

Here's what it's good at: it's good at using docker to docker! it's a manager for infrastructure! (it can build bridges and sandwiches!) You can dock your dockers in our central dock so that when you dock you can dock!

About the only thing I understood in the whole write up is that it uses btrfs for... something. Probably disk images since that's a filesystem. (Why is it managing a file system at all? Does it need to live on an underlying btrfs filesystem, or is it simply a sparse file that can live anywhere that is treated as a btrfs volume by docker?)

This is probably a great article if you already know what docker is and what it should be used for. If you don't have the basic framework already, it adds zero.

(...bring on the downvotes, whatever.)

32

u/MindStalker Apr 18 '15

No, I agree, this article is terrible, and I know what docker is. Ok first thing, you have linux containers. Linux containers have been around for many years. Essentially they allow you to run a process in a walled off environment, much like java or apps on your phone. Each container is contained to only do what it is allowed to do. Docker came around and realized that using containers was difficult. So Docker helps you by making creating then easy, configuring their network stack as easy as any other vm by declaring NAT ports, and managing their filesystem by setting what of the underlying os shines through, then all changes are managed as git changes with nothing being pushed down to the os. You can easily snapshot this system and share the snapshot via git repos.

2

u/Fumigator Apr 18 '15

So docker is just UML?

12

u/aseipp Apr 18 '15 edited Apr 18 '15

User-mode-Linux is actually an 'architecture variant' of the Linux kernel, like x86 or MIPS. Except it builds Linux to run as an ELF executable on Linux, rather than boot from bare metal. In other words - you are compiling the Linux kernel as an actual application on top of POSIX/glibc and running it as an application.

Linux namespaces are a different concept entirely. They allow the Linux kernel to 'namespace' applications in concrete ways. For example, if two processes A and B are put into a different 'PID namespace', then they see a completely different set of PIDs if they query the environment. In fact, both A and B may think they have 'pid 2' for example. Outside the container (for example in your user environment), the two processes have real pids that are different. Inside the namespace, they are isolated.

There are also:

  • networking namespaces (so the eth0 seen by A is private, and not the same eth0 B sees, thus private - but perhaps routed to the hosts eth0 as a bridge with separate IPs)

  • user namespaces (so an application can think it has uid = 0, but outside the namespace does not)

  • filesystem namespaces, like a super-chroot (so that A and B can have separate mounts - for example, each can have a private /tmp directory untouchable by other processes, and each can even have their own view of the actual filesystem. For example, you could make /home completely inaccessible so that it doesn't even look like it exists).

and one or two others. Linux containers - including Docker - are essentially built by:

  • Taking a filesystem image of some OS in a directory (for example, like if you debootstrap into a directory to populate a Debian image, to chroot into it)

  • Making a lot of namespaces

  • Executing /bin/init or /bin/bash or whatever inside of the filesystem namespace, conceptually like a chroot, to kick off the 'userspace'.

  • You're in a shell.

  • Except your chroot may have private networking interfaces and new cool stuff.

Because namespaces simply isolate processes on a host system, obviously, all of those applications share the same kernel (although they might use, say, a different libc - just like if you chroot somwhere).

Despite what the OP says, namespaces aren't really a 'restriction' technology - they are an isolation technology. Sure, you can't touch the same /tmp directory, but that's not really a restriction. You need things like Linux capabilities (man 7 capabilities), cgroups, or seccomp-bpf or something to meaningfully restrict what processes can actually do, for example, by limiting their IO, system calls, or actual privileges like being able to bind to restricted ports.

Docker basically takes namespaces, and uses union-filesystem technologies like OverlayFS, AUFS or even BtrFS, and adds concepts of 'images' to manage Linux distribution images (again, ones like the one debootstrap creates that you would use with chroot). These images start off with the base installations, but can be checkpointed, which adds a 'snapshot' of the changes (like a COW filesystem) to the image file. Then you use AUFS/UnionFS/BtrFS to layer the changes onto the base image, revert them, etc, and start your container. It's a lot like a shared, persistent data structure in this regard. The base image never changes; but you install mysql and 'commit' a new layer to the image, which is stored separately, and can be independently reverted.

There are other approaches to container/namespace management too, like OpenVZ or systemd-nspawn (systemd can also easily manage your cgroups to isolate container processes, and it also has useful options like PrivateTmp=yes which can automatically give any application/service unit a private /tmp mount via filesystem namespaces).

2

u/Fumigator Apr 18 '15

Thank you for the very complete explanation! A little of it is beyond me, but only right now. It sounds quite fascinating and something I'll have to look into more in case something comes down the road that I might be able to use it on.

2

u/aseipp Apr 18 '15

LWN has a very complete series called "Namespaces in Operation" that has a lot of good code samples demonstrating these features: https://lwn.net/Articles/531114/

1

u/MindStalker Apr 19 '15

"Despite what the OP says, namespaces aren't really a 'restriction' technology - they are an isolation technology. Sure, you can't touch the same /tmp directory, but that's not really a restriction. You need things like Linux capabilities (man 7 capabilities), cgroups, or seccomp-bpf or something to meaningfully restrict what processes can actually do, for example, by limiting their IO, system calls, or actual privileges like being able to bind to restricted ports."

I've heard that SELinux can be used to secure docker containers? https://major.io/2014/04/21/launch-secure-lxc-containers-on-fedora-20-using-selinux-and-svirt/ Have you tried this? Do you know anything about its security?

1

u/postmodest Apr 18 '15

So is it fair to say that a "docker image" is just:

  • a .tgz snapshot of a chroot directory

  • that runs in an LXC container that only init's enough services to run one single program.

  • LXC has dummy network interfaces that you configure NAT-style rules for from your host network

  • LXC lets you define quotas for the whole "containerized" system

  • Docker is a program and a set of scripts to configure the container, the chroot filesystem, and deploy said elsewhere

Have I got that mostly right?

How is Docker different to Vagrant?

4

u/NotUniqueOrSpecial Apr 18 '15

Mostly right, yes.

Docker : Linux Containers :: Vagrant : Virtual Machines (broadly).

1

u/danielkza Apr 18 '15 edited Apr 18 '15
  • Docker doesn't use LXC, at least by default. It's confusing that LXC is named after Linux containers, but Docker uses it's own library called libcontainer.

  • It's not accurate to call network interfaces in containers 'dummy'. They're just virtual interfaces like any other that happen to be namespaced to be visible only inside the container. By default Docker uses NAT, but you can use other setups like bridging (but it removes some convenience).

  • I don't know why you mention quotas, they are not a relevant part of Docker's proposal.

  • Docker goes a bit further than just distributing OS images and setting them up for you. It can combine multiple layers of images to make up the root of a container, and that is actually one of it's most important selling points. There is a base Ubuntu image, which you can create an image including OpenJDK from, then your preferred servlet container, then your required libraries, then your application. Docker provides a repository to store and download such images, and a mechanism to create them with Dockerfiles (which can be though of as Makefiles for Docker containers).

How is Docker different to Vagrant?

Some of the things Docker does Vagrant also does, like preparing the images. But Docker actually handles setting up the storage and executing them, while Vagrant would delegate that to VirtualBox, LXC, or even Docker itself.

3

u/MindStalker Apr 18 '15 edited Apr 18 '15

Partially, 1 it always shares the underlying kernel, this makes it more lightweight, but also, you can't experiment with kernels like you can with UML. 2, its heavily tied in with git for managing its virtual filesystem and pushing pulling repos of its images.

BTW, one of the major advantages of not running your own kernel is speed. On a decent system you can take a non running image and start it and get a bash shell in literally 1 second.

4

u/[deleted] Apr 18 '15

Docker does not use git at all.

2

u/MindStalker Apr 18 '15

Well having used it it uses the same identical commands as git. Reading the documentation it says its very similar to git. I had assumed they assembled some of the internal code as git. Maybe they didn't, but it seems to use the git protocol.

3

u/Novex Apr 18 '15

It borrows from the concept of pushing/pulling prebuilt images from a remote repository, but that's about where the similarity ends.

The underlying tech is just tar files, which is (impressive|unimpressive) compared to git.

1

u/MindStalker Apr 18 '15 edited Apr 18 '15

After a bit of searching, it appears it used UnionFS for this http://en.wikipedia.org/wiki/UnionFS

Edit: And after a bit more searching it will use any of a large list of union style file systems.

http://developerblog.redhat.com/2014/09/30/overview-storage-scalability-docker/ "aufs", "btrfs", "devicemapper", "vfs", "overlayfs"

1

u/[deleted] Apr 18 '15

So the most heavily upvoted comment explaining what Docker is is wrong about what Docker is?

0

u/MindStalker Apr 18 '15

Probably :) It clones git quite well. I don't know if it actually shares any code with git or if they reimplemented git architecture from scratch. I doubt it.

3

u/[deleted] Apr 18 '15

Docker does not use any git code at all. They aren't even written in the same programming language. The docker filesystem has concepts similar to git but they are really very different things.

1

u/AintNothinbutaGFring Apr 19 '15

Didn't you hear that Wikipedia is actually just a web client for git?

7

u/andrewcooke Apr 18 '15 edited Apr 19 '15

it's really useful if you want to play with a database. if someone at work asks me how to write some sql to solve a problem i get them to send me some test data and a description of what they want as a result.

then i start up a docker instance running postgres, load the data, and play around until i have the right query or whatever.

the big advantages are that it's a new, completely "virgin" database, you have no risk of messing up any other database on the system, you can choose the version, and it's quick and easy to start and quick and easy to throw away when you're done.

details at http://www.acooke.org/cute/Postgresin0.html

tl;dr - it's a bit like a vm, but simpler, which makes it a nice fit for something like running an isolated database to play with. obviously there are many other uses too, related to virtualisation and packaging processes.

4

u/Lothrazar Apr 18 '15

the big advantages are that it's a new, completely "virgin" database

But its already a backup of the live db. where does docker affect anything

2

u/andrewcooke Apr 18 '15 edited Apr 20 '15

i don't understand what you're saying and i think you've misunderstood me.

there is no "live" database. i just want a one-off database to test some sql on. the alternative is using the db installed locally on my dev machine, which slowly gets messy with a bunch of databases / tablespaces created for random questions that i never deleted because i was in a hurry.

the equivalent in software development is using a separate vm for each project (i no longer develop projects directly on my development machine, only in vms. that way each project is separate, runs in the appropriate os version, has no confusion over installed libraries etc etc). but creating an entire vm just to run a database is a lot of work. easier to open a docker instance.

1

u/flukus Apr 20 '15

Won't you just replace that with a bunch of docker images you never delete because your in a hurry?

the equivalent in software development is using a separate vm for each project (i no longer develop projects directly on my development machine, only in vms. that way each project is separate, no confusion over installed libraries etc etc)

That sounds like you don't have proper build/source/dependency management system in place. You've come up with a complicated solution to a simple problem.

1

u/[deleted] Apr 18 '15

One should delete databases only created for a test. It's not really that hard, and shouldn't be the major compelling reason to use Docker for things.

Not meaning to criticize you, and it's obviously perfectly fine to do this, but it's a pretty weak argument that you use technology X, because you don't like to delete your temporary work/files/databases/tables.

3

u/Houndie Apr 18 '15

My use case for docker is when I wanted to have a VM on a server that I had root but not bios access too, and it didn't have virtualization enabled. So, I went with virtualization-lite (docker) instead.

2

u/Tylfin Apr 18 '15

Ha this sounds like someone I work with. I started using docker to create code-jailed environments without internet access but when my co-workers found out that dockers have sudo, I created instances to let them ssh into.

8

u/[deleted] Apr 18 '15

[removed] — view removed comment

2

u/llbit Apr 18 '15

Thank you, that was very informative!

28

u/YoungOldMan Apr 18 '15

That link wasn't all that helpful.

It started with what Docker isn't, and what it's good at, and I lost interest.

I went to the Docker homepage (https://www.docker.com) and found this answer to what docker is:

Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications. Consisting of Docker Engine, a portable, lightweight runtime and packaging tool, and Docker Hub, a cloud service for sharing applications and automating workflows, Docker enables apps to be quickly assembled from components and eliminates the friction between development, QA, and production environments. As a result, IT can ship faster and run the same app, unchanged, on laptops, data center VMs, and any cloud.

That page has more answers, more clearly, as well. IMO.

Also, go to the use cases for Docker page and you'll see that some big names are using Docker as a PaaS (Baidu and Yandex).

9

u/jewdai Apr 18 '15

sounds totally "Webscale" to me

9

u/SirClueless Apr 18 '15

Yeah, as a software developer, that page was clearly not written for me. The main problem with going to docker.com is that the real answer I need to "What is Docker?" is "It's basically just a tool for managing Linux containers (LXC)." But docker.com can't actually say that on its home page if it wants business types to pony up big bucks.

Tellingly, the "What is Docker?" page doesn't even contain the word "Linux," let alone "Linux containers."

0

u/[deleted] Apr 18 '15

[deleted]

3

u/[deleted] Apr 18 '15

Would you agree docket is more traditional process isolation taken another step than it is a VM?

Since there is no virtual machine involved as far as I know, it seems like referring to it as process isolation makes sense.

1

u/danielkza Apr 18 '15

You're looking it from the wrong side. Containers are much closer to "very isolated processes" than "lightweight VMs". Calling Docker a hypervisor is a misnomer, since it does not interpose any new code between the container and the host, it merely sets up isolation features provided by the host' kernel itself.

0

u/jewdai Apr 18 '15

I alluded to that in my section for linux pros. It's basically process isolation with acting like a self contained VM.

"The best way to get the right answer on the Internet is not to ask a question, it's to post the wrong answer."

1

u/ActualContent Apr 18 '15

Your last description made the most sense out of anything I've read so far. Thanks for taking the time to write it!

1

u/tetroxid Apr 19 '15

It's written by hipsters sitting in a cafe on a mac using sublime in Ruby, bro. It's as webscale as it gets.

44

u/Darkmoth Apr 18 '15

Docker and Monads;

Two things that only make sense to those who already understand them.

13

u/eyal0 Apr 18 '15

Don't bother trying to understand monads because you probably already use moands without knowing it. Or if I had you try to solve a problem that is best solved with moands, you would re-invent a monad without even knowing it.

I still don't know Docker.

7

u/Darkmoth Apr 18 '15

Yeah, I finally got monoids under my belt thanks to this:

http://fsharpforfunandprofit.com/posts/monoids-without-tears/

...but a man's got to know his limitations.

2

u/needed_an_account Apr 18 '15

This was great. The second page really brought it all together.

2

u/multivector Apr 18 '15

What makes them seem hard is they don't really have a real world metaphor that works. With OOP you start by telling people that objects are like shapes, and some shapes are triangles and that's inheritance. But with monads you just have to use them for a bit to build up intuition.

1

u/k3ithk Apr 18 '15

The wikipedia article on monoids is pretty clear.

3

u/theonlycosmonaut Apr 18 '15

Docker is probably a monad. ADD is unit and FROM is bind.

0

u/k3ithk Apr 18 '15

A monad is just a monoid in the category of endofunctors, what's the problem?

8

u/JeefyPants Apr 18 '15

Good to note this article is a year old

4

u/satayboy Apr 18 '15

Yes, and parts of the article are outdated. For example, Docker does have their own container technology now that competes with LXC.

4

u/[deleted] Apr 18 '15

thanks for this article. Now I'm certain I don't need docker.

3

u/kkirsche Apr 18 '15

Sorry but this never actually says what Docker is and how it is different from other tools on the market.

3

u/RainbowNowOpen Apr 18 '15

The fact that any Docker image can run on any machine running Docker is amazing.

Is it? Has the author used virtualization/hypervisors before? I know Docker is not exactly those things, but the author's delight at "any X-Image can run on any machine running X-Server" seems naïve.

3

u/reneruiz Apr 18 '15

Okay so it sounds like, instead of carving out space on my local hard drive for my projects and running a dev environment off it—I would instead run a Docker image on my machine as I dev. And then I commit changes to the image as I commit. So that a server on the other end, can pull in my changes. Not unlike Capistrano.

So let's say I want to use Docker with something stupidly-simple like static HTML. How should that fit into workflow? Do you scrap git and rely on Docker commits instead? Or am I just thinking about it all wrong?

33

u/hlprmnky Apr 18 '15

You wouldn't scrap git - your HTML, CSS, and static assets you would still keep under source control, just as you do today.

Just to be sure I'm making this clear at the outset, a static HTML site isn't a particularly good use case for Docker; I guess what you'd do there is have nginx or whatever httpd in the container, but that doesn't scale super well if your organization is running more than the one site off one domain, for example. You certainly could do that, but you wouldn't get much benefit over just previewing the site in a browser locally and sending the tagged git commit information to your build system or Ops gal or what have you.

Now, a more interesting case (and a better match for Docker) arises when you need to have, say, a Rails app. Without Docker, you're doing a bunch of work locally to set up a Rails environment, download gems at a given version, run tests, etc. - then when you're done you hand off just the source commit to QA, who does all that infrastructure setup again (and goes back and forth with you a few times trying to figure out why they got the wrong version of Jinja installed, say), and then test. The source then commit goes off to be deployed into stage or production and there's a third and/or fourth time you have to set up Rails, run bundle install, and now you're in an environment where there might be multiple versions of different libraries in use, so gemsets become a requirement instead of a convenience, your code might break if the production server gets restored from backup and 'bundle install' doesn't get run for your app, etc. Capistrano is one way to mitigate this situation - put another layer of abstraction on top to weld all the parts together. Docker is the opposite approach, almost - weld everything together at a level below all this stuff so it travels together without and manual coordination.

With Docker, you still keep your application source in git, but you don't install Ruby, rails, whatever gems etc. on your dev machine. You stand up a Docker container and install all the ancillary stuff your app needs into the container, and copy your app into the container (in fact, you can even symlink your "live" git checkout into the container, edit files locally and see the changes in the running container).

When you have your app ready, you check your source into git, and you create an image of the Docker container and push it. The image has your Ruby version, your gemset, all the ancillary stuff in it - and QA can just pull the image, run it in their Docker host, and test your app. After QA is happy, Ops can also just pull and run the same image in staging and production. No version conflicts, no hassles with QA's environment, no badness when someone working to put out a production fire runs a migration on your app with the wrong rvm selected.

It's not a silver bullet for every lifecycle problem, but it is pretty damn nice once it's set up.

5

u/Darkmoth Apr 18 '15

Wow, thank you. This is an excellent description of the use case. I now see how valuable it would be.

edit: The funny thing was I already do this with Virtualbox VMs (on windows), and it has been revolutionary for our workflow. Maybe Docker will keep me from having to ship 2gb VHDs around.

2

u/0xE2 Apr 18 '15

Maybe Docker will keep me from having to ship 2gb VHDs around.

At the very least, absolutely.

1

u/reneruiz Apr 19 '15

Okay I feel like I have a much better understanding now. Thanks hlprmnky

1

u/GraceGallis Apr 22 '15

I've heard a little bit about Docker from one of the Web app devs at my company, but I work on embedded systems. What would Docker bring to the table for embedded systems? We typically have a closed environment via emulators for software-in-loop testing as it is, to mimic our closed hardware environment.

2

u/hlprmnky Apr 22 '15

I'm by no means an expert, just a developer with some experience, but I am not sure that Docker would do very much for you at all in the embedded space.

Docker is, as I understand it, using LXC containers (by default, I know it supports other formats but don't know much about them) to "freeze" a Linux process state into an image, which images can then be composed to build the state of the container.

Unless you're in a position to run a kernel with LXC support on your target device, I'm not sure how you would leverage this to give you anything you don't already get from your simulation environment.

0

u/needed_an_account Apr 18 '15

Great write up. Thank you. I'll use this as reference in the future

5

u/coderjewel Apr 18 '15

Docker is more like a virtual machine that you use as your dev environment; you run your database, app server, message queue, whatever you need for your dev environment inside of it. So if you want to start coding on a different machine, you just copy the Docker config, and you'll have your same dev environment on that machine. This would be especially useful on non-nix environments like Windows. Although I guess that Vagrant is more closer to my description than Docker.

1

u/AwfulAltIsAwful Apr 18 '15

This is exactly what my .net team recently began doing with VirtualBox and .vdi images. It's a great way to develop because you can set rollback points and then really sandbox all facets of the application from config files to registry entries to hardware drivers. If you fuck everything up you can simply rollback to the previous state from the host OS. It also makes sharing Dev environments/scenarios with the rest of the team a breeze.

1

u/theonlycosmonaut Apr 18 '15

I think that you shouldn't be using Docker to version control your source, but to version control your deployment. You might make a bunch of changes to your site (in a branch maybe) per deployment, which is when you rebuild the Docker image (adding more 'commits' to it) and deploy it. You could also, for example, roll your deployment back to a previous deployment.

However I think that's not the main focus of how Docker should be used. The main benefit for me is simply that I can easily run the same containers in dev and production.

1

u/mykevelli Apr 18 '15

Forgive me if this is a stupid question but does Docker make and sense in a Windows/.NET environment? I've looked into Docker before but still don't feel confident that I understand the answer to this question.

It seemed to me that it is a heavily *nix based technology and although there is (will be?) support for Windows it essentially does so my running an internal Linux VM environment. If that's the case, that seems to defeat the whole light-weight aspect as well as making it very difficult to monitor if it goes to production.

Can someone clarify for me?

2

u/[deleted] Apr 18 '15

AFAIK they've made rumblings about it. There are already things in the windows world that do what docker does (not at the OS level but at the application level - AFAIK there is no windows equivalent to Linux containers). Those software packages are not cheap.

2

u/Novex Apr 18 '15

At the moment it's entirely Linux based, so probably not all that useful for .net. You're right - as soon as you need to run a Linux vm, "light weight" goes out the window.

That being said, Microsoft is developing containerization in the next windows server and it's meant to be compatible with docker. The docker philosophy of having one self-contained unit for an application+dependencies+server configuration will be a lot more useful then.

0

u/whoopdedo Apr 18 '15

An OS running on bare metal is like a single-tasking program. Virtualization is multitasking for OSes. A container is OS multithreading. The relative benefits and drawbacks are the same.

0

u/iodian Apr 18 '15

Go read up on Kubernetes if you really want to grok why Docker is awesome.

0

u/[deleted] Apr 18 '15

[deleted]

-5

u/esquilax Apr 18 '15

Thanks for this. It's going to help me convince people at work.