r/docker • • Aug 01 '20

PSA

Docker is NOT a fancy VM Docker should not be treated like a VM

I feel like so many questions on this sub are a result of people not treating Docker like a container and treating it like a VM

SSH, storing data inside the container, post-run configuration... those are anti-patterns. Don’t do them!

23 Upvotes

40 comments sorted by

3

u/spider-sec Aug 02 '20

Saying it’s a VM is not the same as saying it is like a VM. Sometimes it helps to explain how things are different by relating them to something that is similar and that they know.

-4

u/FiduciaryAkita Aug 02 '20

It’s only like a VM in the sense that it’s virtualized, though. This analogy works for someone who isn’t going to work with Docker by as soon as start they need to know the paradigm

3

u/spider-sec Aug 02 '20

Yes, argue with someone who is basically telling you what helped them understand how Docker works. That’ll sure prove your point.

It’s like a VM in that it is virtualized and similar to running another computer. Sure, there are differences, but there are similarities.

1

u/[deleted] Aug 02 '20

What exactly is virtualized (containers)? You literally said the opposite on the post, but now its virtualized again?

1

u/Arinomi Aug 02 '20

I think this was just a poor choice of words. I'd call it abstraction instead of virtualization, because it's not virtualized. Virtualized means, as I've understood it, simulating physical hardware. Containers do no such thing, they simply make their own little corner in the system, cut off from the rest and with their own libraries and packages. Containers can be made to behave and be treated like virtual machines, with certain limitations. This may or may not be the "right" way to do things, but it largely depends on what Docker is for you.

In the very beginning, Docker was a virtual datacenter for me. I learned about the concept of hosting a service consisting of web servers, database servers and a load balancer, which made me fall in love with the general concept of administration, infrastructure and cloud (IaaS). I know full well that making 5 web server containers on a single VM or physical server will do very little to scale my service, but it showed me what it kind of looks like.

1

u/jarfil Aug 02 '20 edited Dec 02 '23

CENSORED

6

u/M08Y Aug 01 '20

The way I explain docker containers to people is as follows, THINK of it as a VM, USE it like a process

4

u/[deleted] Aug 01 '20

That's not really accurate, because thinking of it as a VM would deceive the user into thinking he/she can run any software/process on anything. In reality, you can't run x86 on ARM, Linux containers on Windows, Windows containers on Linux, Windows containers on Mac, etc. without major modifications or compiling everything from source by yourself. I find that this distinction is a fairly huge one, since Docker is usually someone's first alternative to virtualization.

0

u/FiduciaryAkita Aug 02 '20

Yeah containers work fundamentally different from virtual machines. Docker virtualizes the userspace and share a kernel and hardware whereas virtual machines virtualize the hardware itself.

2

u/amishbill Aug 02 '20

I'm another newb, but it seems like a better mental map is to picture a docker container as a magic black box. A plain box with a few connection points, but nothing else. It can access external storage locations for data and to read configuration files that tell it how to work, but you can't store anything in the container itself.

My example is the controller software for my Unifi access points.

  • the software comes pre packed

  • one docker option tells it where to find your configuration settings in local storage. -another docker option tells it how to map an internal IP setting to the IP setting exposed to the rest of the network.

The canned utility does what it does. You can access its control panel through the container's exposed web address, but nothing else. If you want to make a version upgrade, you replace the container itself with a newer version. If you want to change the configuration, you change the docker settings or the configuration files the container is pointed to.

I've probably mis-worded a few things, be it I hope the general theme made it across.

1

u/FiduciaryAkita Aug 02 '20

Yeah this is good! It treats containers as immutable which how they should be used.

2

u/amishbill Aug 02 '20

I should expand this out with proper terminology and make it its own Newb post. Maybe build a spiffy graphic or two.

1

u/M08Y Aug 02 '20 edited Aug 02 '20

I’m well aware that isnt accurate (kubernetes/ cloud architect here). I just find this the easiest way to explain it to a total beginner

Edit: it’s -> isn’t

3

u/[deleted] Aug 02 '20

\o hello, fellow Architect!

I find it easier to explain it as running an app in a sandbox to tech people. More savvy/older admins will understand if you say “lxc” or “jails.”

1

u/throwaway247365_tech Aug 02 '20

I’m not sure what you mean when you say you can’t run Linux containers on windows. I do that literally all the time.

5

u/[deleted] Aug 02 '20

No, then you run your containers in WSL or in a Hyper-V VM. That’s not “on Windows.”

6

u/Karlyna Aug 01 '20

I personally love the docker logo to explain it:

- the boat is your host OS

- the containers are your docker images: they are all running on the host, but isolated from it at the same it with some doors you may open if you need.

56

u/Karlyna Aug 01 '20

This is a poor way to say it imho.

It's easy to yell at newbies that always worked with VM / baremetal servers and have no idea on how container works, but you'd better make them understand whydocker exec -it yourimage sh is better than trying to ssh inside the container, instead of just saying "trying to ssh into a container is anti pattern" (taking this example especially as I saw many lately, but it's true for all points).

Sure, it's "anti-pattern" but still, why "shouldn't I do it" ? If they don't understand the point, they won't be better and correct their mistake.

14

u/AD6I Aug 02 '20

I really agree with /u/Karlyna's thought here. While containers are something different than VMs or baremetal (in fact, VMs and baremetal themselves are different from each other in similar respects to what we are talking about.), its far too easy to throw out the "anti-pattern" phrase, and not approach why.

I cant think of a good SSH example, but Im sure one exists. A real similar example is HTTP/HTTPS. These services are actually so common in containers that we make some special effort to support them. They are, in no way, anti-pattern.

Data inside a container is another similar point. Usually to be avoided, sometimes completely necessary. I can even think of a post-run configuration exception. It would take too many words to dig into the details here, it may even be proprietary, and I should not discuss in detail.

My point is: The rules should be well understood, so that you know when to break them.

2

u/software_account Aug 02 '20

This sounds like experience, the intentional rule breaking comes up in architecture design as well

Best fit beats best practice every time (less so in security)

8

u/magnificbastard Aug 02 '20

Containers are a tool and need to be used appropriately. I concur with /u/Karlyna

For most people, the thought of immutable infrastructure and the carryover of concepts from days past is difficult. I would attack it from the side of the benefits... PSA that everywhere. Show people how amazing it is when you have an understanding of these tools and how to use them.

The first time I showed a coworker the --scale flag it was an immediate... wow how do I do that and interest in the tool. Same as when I pulled up a Linux based MSSQL container on my dev box to test transparent data encryption (Which had a mount point on my local file system so I could persistently map the data and the keys to my box to save my work by the way.). When people see the benefits they become interested, regardless of whether it is Kubernetes, Terraform, Ansible, Docker, Jenkins or any of the other tools that we have at our disposal.

The point is that we need to foster a culture of curiosity and engagement, especially when trying to bridge the divide between silos.

PSA: These tools are all worth learning and will make your life easier.

edit: Spelling

42

u/Gardakkan Aug 01 '20 edited Aug 01 '20

Thanks for your thoughts on newbies. Nice intro to someone who comes here and doesn't know a thing about docker. We're not all pros and we all start somewhere.

Teach us instead of doing a post like this. Would be a lot more constructive.

Also I don't know what you are talking about when you just say SSH and storing data inside the container.

Do you mean don't login to a box? How will use the CLI then?

Do you mean a better practice is to create volumes instead of just going with default volume it will create for the container?

4

u/5fd88f23a2695c2afb02 Aug 02 '20 edited Aug 02 '20

The basic idea is that you should not change containers after you’ve created them. All the other things come from this.

Why? Because the idea behind container orchestration is that containers are made to be disposable - you save yourself a lot of work if you do this right.

With a VM or a bare metal server you have to set it up, maintain it and nurture it. You invest a lot in each server.

With a container you invest the work in creating the container, so you can create 1000 for the same price as one. When you want to upgrade you make a small change to the creation process and then you’re good to go. With the right orchestration tools and load balancing you can dispose of the old containers and switch to the new ones without any users noticing.

10

u/lebean Aug 02 '20

Not OP, but your Docker/Swarm nodes should be exposing a TCP connection that can only be accessed if presenting a certificate from your internal CA. You don't SSH to the nodes to manage your containers/services, you have DOCKER_HOST and the path to your cert in your env so any "docker" command you issue is running against those remote nodes.

What OP is talking about is people who want to SSH into a container. If you're wanting to do that, you've already screwed up and need to start over.

6

u/WH7EVR Aug 02 '20

Not OP, but your Docker/Swarm nodes should be exposing a TCP connection that can only be accessed if presenting a certificate from your internal CA.

For the love of god only expose this on a private network.

3

u/lebean Aug 02 '20

Ah yes, that too... I blame Saturday cookout and beverages.

1

u/lordyellowtail Aug 02 '20

Not OP, but your Docker/Swarm nodes should be exposing a TCP connection that can only be accessed if presenting a certificate from your internal CA. You don't SSH to the nodes to manage your containers/services, you have DOCKER_HOST and the path to your cert in your env so any "docker" command you issue is running against those remote nodes.

What OP is talking about is people who want to SSH into a container. If you're wanting to do that, you've already screwed up and need to start over.

This is great advice, but it assumes the reader is not a complete newbie and actually knows what any of that means.

Not just with docker. It assumes a solid understanding of security certificates (a newbie might not even know if they have an "internal certificate authority," for instance).

A lot of people, like myself, never even heard of docker or installed it until they were introduced to it as a way to more safely and easily install something like, say, pihole.

Which is where I started, only to realize that trying to set up a server that needs to talk to the world outside the container using both IPv6 and IPv4 is in fact non-trivial and. ... well, I'll just say I've learned a lot and leave it at that. :P

0

u/5fd88f23a2695c2afb02 Aug 02 '20

There are a very limited set of reasons that you might want to ssh into a docket container like:

  • during development to check something

  • in production where you really really need to fix something small during an emergency and you don’t have a fully working CI/CD/D setups

1

u/jarfil Aug 02 '20 edited May 12 '21

CENSORED

-22

u/Jdonavan Aug 02 '20

Thanks for your thoughts on newbies. Nice intro to someone who comes here and doesn't know a thing about docker. We're not all pros and we all start somewhere.

You should really learn not to put emotion into purely factual statements.

10

u/WH7EVR Aug 02 '20

You should really learn not to put emotion into purely factual statements.

Wtf?

4

u/CynicPrick Aug 02 '20

Let me ask you something...

Who benefits from this post?

Do you feel better about yourself thinking you've somehow demonstrated superior knowledge about Docker?

Do you think the quality of the sub will improve with your post?

Did you specifically aid someone with these nuggets of wisdom?

Consider this. There's probably more that you don't know about Docker, right this second, than your preaching claims to understand.

Those of us who understand this will always be around to help those who genuinely need the help. Feel free to stay in your cave and feel good about your body of knowledge. I'm sure you've learned all you can.

0

u/ctechdude13 Aug 02 '20

I really hope this is one bad egg our of the entire docker community. Shameful that there are these low standards. I'm just now learning docker and kubernetes. This is the first post I saw on this thread.

3

u/FiduciaryAkita Aug 02 '20

I mean, you can check my comment history. I’m in the comments trying to help people to learn. General PSA’s aren’t a bad thing

0

u/ctechdude13 Aug 02 '20

I'm not here to debate your history with the /r/docker community. That is all ruined by your actions in the original post. I fully agree with /u/Karlyna post and I'll add that quite frankly your attitude towards new comers to the )r/docker community is shameful. If you are a proud docker user and a proud member of this community then you should be constructive not bashing new comers. Period. Have some self respect.

1

u/FiduciaryAkita Aug 02 '20

Saying “hey there’s a lot of questions about this, here’s broad answers” is not bashing newcomers ffs

2

u/Karlyna Aug 02 '20

The message you wanted to give is not (and I fully agree with it), it's more the way it was written that makes us feel like that sadly.

1

u/damnappdoesntwork Aug 02 '20

Sorry but you take it a bit too personal here imo. Throwing words as shameful and bashing.

I do agree /u/Karlyna is a better way to start of, but I guess the point was to get some common misconceptions of docker clear. Treat it like: the first mistakes we all made when staring with containers. After that there is the community, docker docs and the whole internet to get you going and help you out. Which this community will gladly do.

0

u/[deleted] Aug 02 '20

Sober are we?