this post was submitted on 21 Jul 2023
87 points (93.1% liked)

Programming

17358 readers
289 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

Some folks on the internet were interested in how I had managed to ditch Docker for local development. This is a slightly overdue write up on how I typically do things now with Nix, Overmind and Just.

top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 21 points 1 year ago (1 children)

You can have my Docker development environment when you pry it from my cold dead hands!

[–] [email protected] 6 points 1 year ago (2 children)

And keep it that way! We need people on both sides to further spur progress. Plus I'm jealous cause I still don't have a firm grasp on docker.

[–] [email protected] 5 points 1 year ago

Fair!

Python, and its need for virtual environments, is what really drove me to master Docker.

load more comments (1 replies)
[–] [email protected] 17 points 1 year ago (8 children)

I wish he had written why he's so anti-container/docker. That's a pretty unusual stance I haven't been exposed to yet.

[–] [email protected] 16 points 1 year ago (6 children)

Hi!

First I'd like to clarify that I'm not "anti-container/Docker". 😅

There is a lot of discussion on this article (with my comments!) going on over at Tildes. I don't wanna copy-paste everything from there, but I'll share the first main response I gave to someone who had very similar feedback to kick-start some discussion on those points here as well:

Some high level points on the "why":

  • Reproducibility: Docker builds are not reproducible, and especially in a company with more than a handful of developers, it's nice not to have to worry about a docker build command in the on-boarding docs failing inexplicably (from the POV of the regular joe developer) from one day to the next

  • Cost: Docker licenses for most companies now cost $9/user/month (minimum of 5 seats required) - this is very steep for something that doesn't guarantee reproducibility and has poor performance to boot (see below)

  • Performance: Docker performance on macOS (and Windows), especially storage mount performance remains poor; this is even more acutely felt when working with languages like Node where the dependencies are file-count heavy. Sure, you could just issue everyone Linux laptops, but these days hiring is hard enough without shooting yourself in the foot by not providing a recent MBP to new devs by default

I think it's also worth drawing a line between containers as a local development tool and containers as a deployment artifact, as the above points don't really apply to the latter.

[–] [email protected] 14 points 1 year ago (1 children)

If your dev documentation includes your devs running docker build, you're doing docker wrong.

The whole point is that you can build a working container image and then ship it to a registry (including private registries) so that your other developers/users/etc don't have to build them and can just run the existing image.

Then for development, you simply use a bind mount to ensure your local copy of the code is available in the container instead of the copy the container was built with.

That doesn't solve the performance issues on Windows and Mac, but it does prevent the "my environment is broke" issues that docker is designed to solve

[–] [email protected] 2 points 1 year ago

The whole point is that you can build a working container image and then ship it to a registry (including private registries) so that your other developers/users/etc don’t have to build them and can just run the existing image.

Agreed, we still do this in the areas where we use Docker at day job.

I think the mileage with this approach can vary depending on the languages in use and the velocity of feature iteration (ie. if the company is still tweaking product-market fit, pivoting to a new vertical, etc.).

I've lost count of the number of times where a team decides they need to npm install something with a heavy node-gyp step to build native modules which require yet another obscure system dependency that is not in the base layer. 😅

[–] [email protected] 13 points 1 year ago (1 children)

Cost: Docker licenses for most companies now cost $9/user/month

Are you talking about Docker Desktop and/or Docker Hub? Because plain old docker is free and open source, unless I missed something bug. Personally I've never had much use for Docker Desktop and I use GitLab so I have no reason to use Docker Hub.

[–] [email protected] 6 points 1 year ago (1 children)

I believe this is the Docker Desktop license pricing.

On an individual scale and even some smaller startup scales, things are a little bit different (you qualify for the free tier, everyone you work with is able to debug off-the-beaten-path Docker errors, knowledge about fixes is quick and easy to disseminate, etc.), but the context of this article and the thread on Mastodon that spawned it was a "unicorn" company with an engineering org comprised of hundreds of developers.

[–] [email protected] 9 points 1 year ago (1 children)

My point is that Docker Desktop is entirely optional. On Linux you can run Docker Engine natively, on Windows you can run it in WSL, and on macOS you can run it in a VM with Docker Engine, or via something like hyperkit and minikube. And Docker Engine (and the CLI) is FOSS.

[–] [email protected] 5 points 1 year ago (1 children)

I understood your point, and while there are situations where it can be optional, in a context and scale of hundreds of developers, who mostly don't have any real docker knowledge, and who work almost exclusively on macOS, let alone enough to set up and maintain alternatives to Docker Desktop, the only practical option becomes to pay the licensing fees to enable the path of least resistance.

[–] [email protected] 9 points 1 year ago* (last edited 1 year ago) (2 children)

We are over 1000 developers and use docker ce just fine. We use a self hosted repository for our images. IT is configuring new computers to use this internal docker repository by default. So new employees don't even have to know about it to do their first docker build.

We all use Linux on our workstations and laptops. That might make it easier.

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago)

We all use Linux on our workstations and laptops. That might make it easier.

You are living my dream!

I think this is the key piece; the experience of Docker on Linux (including WSL if it's not hooking into Docker Desktop on Windows) and on macOS is just so wildly difference when it comes to performance, reliability and stability.

load more comments (1 replies)
[–] [email protected] 8 points 1 year ago (2 children)

Docker builds are not reproducible

What makes you say that?

My team relies on Docker because it is reproducible…

[–] [email protected] 4 points 1 year ago (2 children)

Highly recommended viewing if you'd like to learn more about the limits of reproducibility in the Docker ecosystem.

[–] [email protected] 3 points 1 year ago

Here is an alternative Piped link(s): https://piped.video/watch?v=pfIDYQ36X0k

Piped is a privacy-respecting open-source alternative frontend to YouTube.

I'm open-source, check me out at GitHub.

load more comments (1 replies)
[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (2 children)

You might be interested in this article that compares nix and docker. It explains why docker builds are not considered reproducible:

For example, a Dockerfile will run something like apt-get-update as one of the first steps. Resources are accessible over the network at build time, and these resources can change between docker build commands. There is no notion of immutability when it comes to source.

and why nix builds are reproducible a lot of the time:

Builds can be fully reproducible. Resources are only available over the network if a checksum is provided to identify what the resource is. All of a package's build time dependencies can be captured through a Nix expression, so the same steps and inputs (down to libc, gcc, etc.) can be repeated.

Containerization has other advantages though (security) and you can actually use nix's reproducible builds in combination with (docker) containers.

[–] [email protected] 10 points 1 year ago (1 children)

That seems like an argument for maintaining a frozen repo of packages, not against containers. You can only have a truly fully-reproducible build environment if you setup your toolchain to keep copies of every piece of external software so that you can do hermetic builds.

I think this is a misguided way to workaround proper toolchain setup. Nix is pretty cool though.

[–] [email protected] 4 points 1 year ago* (last edited 1 year ago) (1 children)

That seems like an argument for maintaining a frozen repo of packages, not against containers.

I am not arguing against containers, I am arguing that nix is more reproducible. Containers can be used with nix and are useful in other ways.

an argument for maintaining a frozen repo of packages

This is essentially what nix does. In addition it verifies that the packages are identical to the packages specified in your flake.nix file.

You can only have a truly fully-reproducible build environment if you setup your toolchain to keep copies of every piece of external software so that you can do hermetic builds.

This is essentially what Nix does, except Nix verifies the external software is the same with checksums. It also does hermetic builds.

[–] [email protected] 4 points 1 year ago (2 children)

Nix is indeed cool. I just see it as less practical than maintaining a toolchain for devs to use. Seems like reinventing the wheel, instead of airing-up the tires. I could well be absolutely wrong there - my experience is mainly enterprise software and not every process or tool there is used because it is the best one.

[–] [email protected] 2 points 1 year ago (1 children)

@nickwitha_k @uthredii I’d like to think a better analogy would be that nix is like using a 3D model of a wheel instead of a compass and a straightedge to make wheels hehe 🙃

[–] [email protected] 1 points 1 year ago

I quite like the sound of Nix, every time I touch on it but haven't really dug in yet. You're making me really want to though.

[–] [email protected] 1 points 1 year ago (1 children)

I just see it as less practical than maintaining a toolchain for devs to use.

There are definately some things preventing Nix adoption. What are the reasons you see it as less practical than the alternatives?

What are alternative ways of maintaining a toolchain that achieves the same thing?

[–] [email protected] 2 points 1 year ago

I see it as less practical mainly due to the extant tooling and age/maturity of the project.

The ways that I'm most familiar with are use of software like Artifactory - basically a multi-repo. Using such a tool, any package or artifact can be readily retained for future use. Then, for builds, one only needs to ensure that it is used as the package source, regardless of type (PyPy, Docker image, binary, RPM, etc).

Alternatively, one can use individual repos for any relevant package type but that's a bit more overhead to manage.

[–] [email protected] 2 points 1 year ago (1 children)

I’ll certainly give this a read!

Are you saying that nix will cache all the dependencies within itself/its “container,” or whatever its container replacement would be called?

load more comments (1 replies)
[–] [email protected] 4 points 1 year ago

Appreciate the in-depth response! I've always been interested in Nix but I'm scared of change lol. And I'm a single systems administrator on a team of mostly non-technicals so large changes like that are .. less necessary. Plus you know, mostly dealing with enterprise software on windows unfortunately. One of these days.

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago)

Docker performance on macOS (and Windows), especially storage mount performance remains poor

I remember when I first got a work Macbook and was confused why I had to install some 'Docker Desktop' crap.

I also learnt how much Docker images care about the silicon they're built on... Fucking M1 chip can be a pain...

[–] [email protected] 7 points 1 year ago (1 children)

Docker is like, my favorite utility tool, for both deployment AND development (my replacement for Python virtual environments). I wanted to hear more of why I shouldn’t use it also.

[–] [email protected] 2 points 1 year ago (1 children)

Right? If it's about ease of insight into containers for debugging and troubleshooting, I can kinda see that. Although I'm so used to working with containers it isn't a barrier really to me anymore.

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago)

yup. it's a breeze especially for interpreted langs. mount the source code, expose the ports and voila. need a db?

services:
  pg:
    image: postgres
[–] [email protected] 6 points 1 year ago

@astral_avocado @LGUG2Z That definitely would’ve been helpful for readers new to the Nix scene, but I don’t think that’s the purpose of this article. It’s written as more of an example of a way to move to Nix, rather than an opinion piece on why you should move away from Docker.

I won’t try to argue why you should switch. However, I would recommend you look into the subject more, Docker is a great tool, but Nix is on a diffeeent level 🙃

load more comments (5 replies)
[–] [email protected] 8 points 1 year ago* (last edited 1 year ago) (1 children)

I use a similar approach, but I went further by creating a system that compose like docker-compose would. The trick was to write my own nix function mergeShells.

https://her.esy.fun/posts/0024-replace-docker-compose-with-nix-shell/index.html

For now, I am pretty happy with it. Also, I put the init script inside nix-shell and not in external files and use exit signal to cleanup the state.

[–] [email protected] 2 points 1 year ago

Thanks for sharing this! Added to my weekend inspiration/reading pile. 🙏

[–] [email protected] 8 points 1 year ago

Kind of cool if your production infrastructure can match. But for most companies (ie, Fortune 500 and some medium companies) implementing this would need a force majeure.

Decades of software rot, change in management, change in architecture, waxing and waning of software and hardware trends, half assed implementations, and good ole bottom tier software consultation/contractors brought into the mix make such things impossible to implement at scale.

Once worked at a company where their onprem infra was a mix of mainframe, ibm / dell proprietary crap, Oracle vendor locked, and some rhel/centos servers. Of course some servers were on different versions of the OS. So it was impossible to setup a development environment to replicate issues.

For the most part, that’s why I still use docker for most jobs. Much easier to pull in the right image, configure app deployment declaratively, and reproduce the bug(s). I would say 90% of the time it was reproducible. Before docker/containerization it was much less than that and we had to reproduce in some non production environment that was shared amongst team.

[–] [email protected] 3 points 1 year ago

I’m surprised no one has mentioned either of the following solutions as alternatives to this explanation (and docker) that still uses Nix:

[–] [email protected] 3 points 1 year ago

Related, this article talks about combining nix and direnv: https://determinate.systems/posts/nix-direnv

Using these tools you are able to load a reproducible environment (defined in a nix flake) by simply cding into a directory.

[–] [email protected] 2 points 1 year ago (1 children)
load more comments (1 replies)
load more comments
view more: next ›