211 points · by MatthiasPortzel · 3y ago · 218 comments
- what filepaths are important (both for volume-mounting and for files output by the container)
- what envvars (or CMD, or ENTRYPOINT) are needed
- what ports will be opened, and what they mean
- what protocols the ports talk
...etc. I'd really like containers to one day behave like software libraries: you pass in a set of documented parameters, and get an object that you can pass around and use in return.
e.g. nginx in isolation is useless. But is really useful when you want to expose a bunch of other services on a single http(s) interface.
When you are working at the compose level you are thinking about an ecosystem of services working together and of course then you are you using the compose tools to achieve that. But managing each component in isolation is much more tedious.
Uh, of course they do, since they say nothing about how to run a container. Dockerfiles encode an image (also not really deterministically, contrary to the common belief, but that's details), not a container.
And docker-compose.yaml represents making a bunch of containers from images. These are completely separate things.
But sure, for local deployment docker-compose is awesome.
Not sure I follow? Docker Compose in no way trys to replace a Dockerfile or docker images - every container you specify in one still has the exact same Dockerfile, compose can't replace this.
I also think Compose is a fantastic tool, but to start comparing to Dockerfiles and Kubernetes suggests not understanding what Compose is for.
The thing Compose does better than a bunch of loose dockerfiles especially is document in a runnable fashion the relationships between key containers in a given stack. This information alone can tell you a lot about how you would deploy in more complex environments, as well as giving you something you can usually deploy instantly with a docker compose up for local development work.
Without compose, you typically have to rely on loose documentation much more, which may be stale or outdated and obviously isn't "runnable" like docker compose is. I also find it far easier to understand what volumes are critical for persistence when its coded in the Compose yaml, vs a bunch of -v args in the documentation for a docker run command launch.
>t. The guy who gets endlessly tired of having to unfsck the layers of abstraction into something mere mortal devs/testers can reason through about.
These days you can even build, and deploy a debuggable image from an IDE easily so you don't need to bridge the network.
I've taken to replacing docker compose files with bash scripts for my personal projects. So far, it's been OK.
This site might help: https://www.composerize.com/
Also you can also run that site in docker.
I'm sorry but this is just incredibly messy for anything that's not trivial. We have tons of docker-compose services, all instantiated N times and each having their own network, secret, volume, env var, target etc configuration. In my mind it doesn't make sense to replace a 100 line YAML with a gargantuan messy shell script only old graybeards understand.
That's why I said "personal projects".
If anyone has good ideas, please share!
Setting up an N-node Cassandra cluster: https://docs.kurtosis.com/how-to-parameterize-cassandra#inst...
Idempotent runs documentation: https://docs.kurtosis.com/concepts-reference/idempotent-runs
If your job is to write config all day, and nothing else (which is the only reason I think you'd care that much to dislike docker compose JUST because of yml), maybe the thing you actually dislike is the nature of the job?
What's interesting is that for those 3 there are often better versions. Docker Engine is not used in a number of popular examples – GCP for example uses their own engine if I remember correctly. There are other pluggable runtimes. The Docker desktop app isn't great, and is now expensive, compared to a number of cheaper or free or open source alternatives. And Docker Hub is basically just for free public publishing, as Docker registries are so commoditised.
I've always felt that the best bit of Docker is the file format and the UX around that. But that's not something Docker-the-company has managed to monetise.
Docker hub is absolutely the most popular registry for open source software and configured as default address for kubernetes.
Nothing of it is irreplaceable for sure. But Docker made a big contribution to container world, regardless.
It's obviously important for macOS, because macOS does not support docker containers.
While Windows supports docker containers, most docker containers are built for Linux, so Docker Desktop is important for Windows as well.
Now for Linux you can run docker engine on the host, if you're proficient with Linux. However some people use Docker Desktop on Linux as well. I could imagine that you can run very old host Linux this way.
I, personally, avoid docker desktop on macOS. Right now I'm using remote Linux VM and in the future I'll use Linux in VM, configured manually. However I've yet to find out how to mount host directories inside that VM containers. Some magic.
I am using Rancher desktop and number of bugs and lack of features would make paying for Docker desktop worthwhile if I used it more than ~1 hour per week.
I didn't even know Docker Desktop existed until couple months ago. My wife works on MS Windows and she needed to run someone's project that was for some reason distributed in Docker images... She couldn't get Docker installed on Windows, but that's kind of expected as everything is kind of screwy there... so, I had to use Web search to figure out what is the way to do it (she did try to get Docker Desktop).
I ended up configuring Hyper-V (solely because it comes bundled with the system) and installing Docker in some Arch VM I set up for that.
I cannot claim that this is a "comfortable" setup, but given the overall bad UX of that OS and that Docker isn't designed to run on it from the start, I think it's an OK solution.
I briefly tried opening the Docker Desktop GUI, and I just cannot understand why would anyone need that specific thing... it just seems to make everything worse at the baseline. You immediately miss the convenience of being able to feed the output it produces into grep / pager or to combine information extracted from one output with the input into another operation.
I have a hard time calling Dockerfile declarative when the RUN statement literally runs a sequence of user provided shell commands in a container. Is a shell script declarative or imperative?
It is structured and mostly results in an easy to understand set of instructions to create a container image. But it is a set of instructions and you can shoot yourself in the foot (especially with reproducibility)
# syntax=docker/dockerfile:v1
Which is a Docker image that translates the declarative syntax into the commands sent to the low-level builder. That syntax is pointing to a Docker image name and tag (`docker/dockerfile:v1`) that Buildkit pulls down and feeds the passed commands into. Technically, that could be anything. If you wanted to put in the work, you could write a Buildkit frontend for Ansible or Chef and use that to configure the image.So, on the list of “4 things Docker is”, they were wrong on the first one.
1. Be as reproducible as possible. e.g. if you're using RUN to download a file, check the hash to ensure that someone building the image in the future gets the same file. Lock your dependency versions wherever possible. Sometimes this is impractical, e.g. OS packages in most Linux distros expect other packages to be mostly up to date.
2. Separate RUN commands so that more frequently changed content is created later in the Dockerfile, to maximize caching.
Docker Engine uses a Dockerfile as an instruction to build a Docker Image
Edit: perhaps it is idiomatic somewhere in the world to say "builds X to Y", but not in the U.S., in my experience. Could be similar to British "different to" as compared to American "different than" or "different from".
It’s very hard to get reproducible output. It’s even fairly hard to get output where the inputs are well controlled.
It can’t do a clean crossbuild — you have to run the container to build it. As a side effect, you need all the tooling to install things into the container to be in the container. (Yes, there are workarounds. They’re ugly.)
It leaves trash behind. You need to fight with it to even get /tmp to be temporary.
It has no usable efficient way to supply large input files. You can bind-mount into a RUN, but getting permissions right when doing so is an uphill battle.
As a trivial example, network access for RUN should be opt-in, not opt-out. The fact that the easiest ways to pull data in involve things like RUN wget is a design error.
A much better approach would be to have packages that install with as little script involvement as possible. Most Linux images are put together using rpm or deb packages and, other than pre/post-install scripts (which are not usually particularly necessary), package installation is fundamentally reproducible and does not require running the image. A good image building system IMO would mostly look more like:
INSTALLPACKAGES foo bar baz
And dependencies would get solved and packages installed, reproducibly.
Do you mean the image format? The Dockerfile as a recipe for building an image seems like it can be replaced pretty easily with a nicer interface whenever someone feels like building one. But the image format will probably continue to be supported for some time.
https://github.com/docker/for-win/issues/1549
Still pissed my HP Windows laptop was bricked from it a few months ago. I’ll never use it for anything.
(Not saying that doesn't suck, just arguing with the terminology.)
But reinstall Windows crashes, USB recovery drive only helps copy files from command line, system restore points all crash. “OS corruption” sounds like it can be repaired while keeping files, but this is worse than that.
If it corrupts your OS and it corrupts your files, that sucks, but it's not bricking unless it's impossible to install a working operating system.
This is a grand oversimplification/misconception.
The Dockerfile is just a description on how to build a container image. Running a container on an engine is a different story.
It's not reasonable at all. If someone is trying to learn Docker and they read this misleading article, they will think they can somehow run their Dockerfile as a container, and they will be wholly confused as to why it's not going to work out.
I create my docker images with Bazel/crane [1]. (For reproducibility.)
There are no Dockerfiles at all.
---
The .py example is bad because there is nothing else (AFAIK) that produces .pyc.
A pedant might similarly go the other way and say "C isn't just a compiled language, because personally I use the Ch C interpreter".
I don't think it's a good enough reason to avoid reasonable simplifications in technical writing because "Well actually, advanced users have an edge case where that assumption doesn't strictly hold....". The only way for anyone to get a reasonable understanding of anything complex is by starting with small simplifications and generalizations.
But you cannot run a Dockerfile, in the same way you cannot run a C++ source file as an executable. It needs to be compiled first.
But, yeah, if the article wanted to clarify instead of obscuring the functionality of Docker, the one we know and use, then saying that it runs the Dockerfile is misleading. I mean, it does run it to builds an image, that's how it build the image, but then readers need an explanation for why there are images and why do they need them, if all they do is running Dockerfiles, and that's where the "explanation" becomes worthless.
The article is incorrect. If you don't download or build the Docker image from the Dockerfile, you will not be able to run a container from the Dockerfile alone.
Docker is a command that can build, fetch, and run docker images from a docker registry and orchestrates running those typically on a linux host or virtual machine.
A docker image is a set of hashes that identify layers in a layered filesystem. A docker registry stores those layers and the docker looks up layers from the registry. The combined layers form a filesystem that is mounted when you run the docker image. A running docker image is called a docker container.
To create a docker image with docker, you use a Dockerfile that specifies a sequence of steps that modify the layered file system, typically starting from a base image that is specified in the first line.
The company Docker Inc. is a major contributor to the open source docker code base and also owns and runs a popular docker registry called Docker Hub, which is what the docker command uses as default place to look for docker images.
While docker is popular, there are alternative tools that are able to run docker images. For example Kubernetes implements its own way to run docker images. Likewise, there are build tools that produce docker images without using the docker command or a Dockerfile. And the docker registry API is simple enough that you don't need docker to fetch layers either.
Consequently, there are several popular tools in this space. That do similar things with varying degrees of compatibility. Many of these can run docker containers from Docker Hub.
I think you meant to say
"Docker is more than just one thing.", right?
This is like saying "Tylenol/Panadol is a painkiller and a fever reducer" without ever mentioning that it is a branded offering of the generic drug Acetaminophen/Paracetamol. We need to start using generic terms for technologies, not product names first. E.g. "Reactive Web Components" could be React, Preact or a number of other libraries/frameworks.
- Dockerfile.
- Docker image.
- Docker container.
- Docker repository.
the docker desktop and docker hub is an implementation of one of those, other concepts like overlay filesystem as well.The Dockerfile format is not declarative.
Declarative means you define the state you want
Imperative means you define the commands to run
Dockerfile is 100% imperative
https://zwischenzugs.com/2023/04/27/is-it-imperative-to-be-d...
TL;DR you're probably right, but it's more complicated than I thought.
https://github.com/nlewo/nix2container/blob/master/examples/...
(disclosure: I have contributed to that repo)
this is not looking particularly more declarative than docker
Some is declarative, e.g. `FROM`, `ENV`, `EXPOSE`. While on the other hand `RUN`, `CMD`, etc. is fully imperative.
`FROM` also has more use cases when using multi stage builds.
Acutally, come to think of it, since `RUN` may depend on any other Dockerfile statement (even `EXPOSE` might make a difference in code), does this mean that even a single imperative statement that is introduced in some language, makes the language imperative?
In comparison, a Nix file is actually declarative ("I want my result system to have this" as opposed to "Do this to get me towards my result system"), and is actually reproducible.
But notice the sizes of both a Docker image (many megabytes) and a Nix file (a couple of K)...
A Dockerfile provides no guarantees that it will succeed, is what I was getting at- which is why people download Docker images to begin with, because the build product is guaranteed to work, since it's immutable at that point.
If you pretend that COPY means with these files like those files on host machine as of execution time, RUN means with this command executed at build time, etc., then even Dockerfile becomes fairly declarative. Every declaration defines a new immutable layer with its own unique hash, it’s just that some declarations can easily be used in ways that make the outcome vary based on the state of the entire world as of build time.
Just as in Ansible you can use “declarative” YAML in a very imperative lasagna of a setup, you can do the same with a Dockerfile, Nix, Haskell, or Python. You can also get pretty close to purely declarative bliss with any of them, but it will grow impractical before that point.
COPY . .
RUN npm install
And: COPY package.* .
RUN npm install
COPY . .
The first file reruns npm install every single time any file changes in the code. The second only reruns npm install if the packages change. That can make the difference between a 5-minute build and a 5-second build, so it's not a small optimization.Given how important the order of instructions is, it's hard for me to think of it as declarative. It fits better in my mind as a sequence of instructions, which is the very definition of imperative.
I find Docker an interesting example of a fundamentally elegant approach that, possibly to facilitate commercialisation, was documented in a way that, instead of imposing any particular culture (such as, say, Nix or Haskell), strongly aligned with the preexisting culture of operations and system administration—the resulting ease of adoption and popularity (and, I assume, broadly deserved financial well-being of the original creators), however, could not come without a variety footguns along the lines of which you have described.
I get why it is the way it is, but if it were more declarative, it would be easier to manage Dockerfiles through changes, security updates, etc.
Dockerfile is intentionally bare-bones. It just gives you RUN straight up, no scary hidden option, but it’s up to you how to use it. If you want to write imperative, you can. If you don’t write imperative, pin everything to a hash, shell out only to Dhall and Prolog, it can get very declarative…
…at a cost. The fact that people do not tend to go this route means equally that 1) they are lazy, and 2) using RUN this way is pragmatic.
This blurs the meaning of "declarative" to the point of meaningless.
Consider the following pseudocode:
x = 5
print x
x = 10
print x
This is clearly 'imperative'.But from the perspective of 'each line of code declares a new program', then we consider the code snippet a declaration of a program.
> Just as in Ansible you can use “declarative” YAML in a very imperative lasagna of a setup
One of the things which makes Dockerfiles imperative is the sequence of Dockerfile commands is significant; if you swap the order of a COPY, RUN to a RUN, COPY, the result changes significantly.
> But from the perspective of 'each line of code declares a new program', then we consider the code snippet a declaration of a program.
The critical difference is that each line in a Dockerfile yields (declares) a filesystem state which can be referenced and recreated. In contrast, in your example, I have no way to say "give me a snapshot of the system between the third and fourth instructions".
Dockerfiles have all sorts of rules and restrictions that make these semantics possible. You cannot create loops; there is nothing like a "function", at least within the context of one Dockerfile.
> One of the things which makes Dockerfiles imperative is the sequence of Dockerfile commands is significant; if you swap the order of a COPY, RUN to a RUN, COPY, the result changes significantly.
I reject this line of reasoning, simply because decalative languages are indeed order-dependent:
let y = f(g(x))
is different than: let x = g(f(x))
Much in the same way that these are different: FROM x AS y
RUN g
RUN f
vs FROM x AS y
RUN f
RUN gThe alternative is to draw a clear line where there is none.
> One of the things which makes Dockerfiles imperative is the sequence of Dockerfile commands is significant; if you swap the order of a COPY, RUN to a RUN, COPY, the result changes significantly.
By that logic you can call every Nix program “imperative”. They are sequences of strings, the order of which matters. The horror!
A Docker image is a stack of layers. Every layer points to a preceding layer. It’s not a huge leap from that structure to a fairly elegant sugar of a string array, where each string is a declaration that applies to preceding layer thus describing the next one. I don’t see anything fundamentally imperative about it; it can be used in imperative ways, but anything can.
But the syntax itself is conducive to imperative image definitions, and they are by far the most common
“FROM ubuntu:latest” is pretty declarative then…
Here's an example Dockerfile:
FROM McDonalds Cheeseburger HappyMeal
RUN Get ketchup packets
RUN Squirt ketchup on fries
RUN Dump happymeal on plate
The first is declarative, a menu, you point at what you want and software makes it so.
The rest is a recipe, an imperative, a command, you tell software to perform, and software makes it so.
In point of fact the image side of a Dockerfile, where an image is a DAG of other images referenced by an immutable ID or pointer to hosted content, is "100%" declarative. It's only the "build" syntax that is ordered.
The "image side of a Dockerfile" isn't a Dockerfile, it's an image, more specifically an image in the OCI Image Format [0]. A Dockerfile is just the most common syntax for controlling software that can create an OCI image (such as Docker and Podman).
You could argue that the OCI Image Format is declarative, but that's not relevant to OP's comment about Dockerfiles.
Hopefully Matthias gets into blogging more.
I miss the good old days of lots of programmers blogging.
Which keeps all kind of mounts and virtual networks alive that you don't need and that interfere with other things you want to do.
For example I was on a train in Germany recently and could not use the Wifi. Why? Turned out the docker daemon occupied the IP range the Train Wifi uses. While I was not using docker at all.
Second, Kubernetes is a dev-friendly app management tool. Start 5 copies of this app, restart if it fails, mount this config file, etc. Most Kube apps look roughly the same across teams and companies, so skills are transferrable.
Third, the Kubernetes API is a standardization layer between compute/cloud capabilities.
Fourth, the Kubernetes Container <foo> Interface (CxI) is a implementation layer to plug in to compute capabilities. You can swap Docker, CRI-O, etc with the Container Runtime Interface (CRI). Use cloud block storage with Container Storage Interface (CSI).
Fifth, Kubernetes custom resources (CRDs) are a standardized extension point for building custom behavior into a cluster in a sane way.
1) an API server and spec definition for infrastructure and applications
2) a distributed database to store API state
3) agents to apply the API definition into “real” systems
Also, Windows containers are a thing.
https://docs.docker.com/build/buildkit/
I am particularly interested in build systems, so I am biased, but I think this is one of the coolest things coming out of Docker. It is a bit painful to see so much fanfare at DockerCon about Docker Desktop stuff, and so few mentions of more foundational things like buildkit and rootless container support.
1. The Dockerfile specification
2. A tool to turn a Dockerfile into an OCI image (or actually, multiple tools, since we have "normal" docker and docker buildx)
3. A tool to run OCI images (I don't even know if this works for images not generated by docker)
4. Docker Desktop
5. Docker Hub
Or on Windows natively, using native Windows containers, assuming the image you want to run is a Windows application and not a Linux one.
[0] https://blog.janissary.xyz/posts/docker-gripes , see `Conclusion` section
Only if using Linux containers.
Windows has native containers support.
For who target Linux as deployment platform, as is common, Docker instead forces to run the Linux version of interpreters and libraries on a Mac or Windows. On top of a Linux mini VM. Could not be otherwise?
"Docker Engine which takes a Dockerfile and runs it on a Linux host natively" no, not really, you have to build the dockerfile into a container. There is a lot of different steps between.
This post is four things and i'll leave it to the reader to figure it out
docker pull ubuntu
Which doesn't feel right. I wish the hub URL was mandatory.Containers aren't a new concept. But in today's world, we're usually talking about the intersection of three Linux features:
* namespaces bundle resources (processes, disk, I/O, etc.) together, isolating them from each other. They're a teacher with a class full of rowdy kids.
* cgroups (control groups) limit and audit how many resources a group of processes can use. They're traffic cops.
* Union File System sits on top of another file system. Anything in the underlying file system is visible, but writes and new files only appear in the UnionFS mount. This layer can be thrown away at the end of a session, leaving the base filesystem pristine. It's the tracing paper you used as a kid when you were learning to draw.
Processes in a container run on the same kernel as the other apps you run, but they're isolated, controlled, and kept from scribbling all over the disk. Add some tooling and standards and you have the foundations of modern #softwaredevelopment !
Think of a container as a fancy chroot.
Imagine that:
1. You have a whole separate Linux installation in some random folder.
2. You ask your OS to launch some process, and to "trick" the process into thinking that "$YOUR_FOLDER" is actually "/".
3. You maybe also ask your OS to add some extra isolation (network, devices, /proc, etc).
4. The term "container" refers to the chroot, the isolation rules, and usually the process-tree running inside of it.
5. While a container is alive, you can also ask the OS to run some other programs that exist inside of the container's sandbox
Docker is a tool that creates and manages containers. In Docker's view of the world:- Containers are made by extracting .tar.gz files into some folder and asking the OS to create a sandbox where that folder is a "fake" root directory.
- Those .tar.gz files are called "images".
- Docker can download images from the internet, or you can build your own by asking it to follow the steps contained in a Dockerfile.
An image is an easy way to deliver an entire software package. A container is the place where your image will run.
It's an individual OS with a filesystem of its own, based on the "image" and what is pre-installed (such as an OS, plus, if you choose: some extras pre-installed based on your project need.).
You can link your laptop or server (AKA your "host" computer) to it through Docker Volumes. And, you can link containers together through Docker Networks, for example.
So, you can see how a single compartmentalized OS (a "container") can: 1. interact with another computer's file system and 2. interact with another computer on a network. And, each one can be quite customized.
So, a container is an OS + filesystem* + network*
* = can be connected to others to transfer data
state of the art?/ information needed -First, the Dockerfile file format for declaratively describing a machine (operating system, installed packages, processes, etc). -Second, the Docker Engine which takes a Dockerfile and runs it on a Linux host natively, without a virtual machine. -Third, the Docker Desktop app which takes a Dockerfile and runs it on a Mac or Windows host, using a Linux virtual machine. -Fourth, the Docker Hub container repository which allows a community to share Dockerfiles for common configurations.
problem that could arrive/why this is important Often, when people evaluate Docker or make statments about “Docker,” they’re referring only to the Docker Engine.
conclusion But most of the time, this is not a useful view to take. Most of time, the practicality of Docker comes from a combination of all four of these things."
I wonder what proportion of people think that Docker enforces the separation between inside and outside a container.