7

I'm creating a development setup for a web app with Docker. We have developers running in Windows, Mac, and Linux. Everyone will be using Linux containers, but there are still issues that only affect Windows users.

I'm not looking to run the application differently than production. Rather it's the tooling around the developer setup that needs to be different.

Is there a way to detect the Operating system of a Host from within a Docker container?

4 Answers4

1

Do you really want to do this?

I know you're not happy with a frame challenge answer, but please bear with me.

The problems you're facing appear because running Linux-based Docker on Windows is a hack. Certainly you can run into Windows filesystem issues, but there may be other issues I'm not aware of.

Now, as I understand, you want to add platform-specific workarounds to your project to allow running it in a VM on Windows hosts. Based on my experience I would recommend avoiding this.

  1. Windows is not a target platform for your project. Adding solutions for Windows-specific issues introduces unnecessary complexity. Unnecessary complexity means increased maintenance cost and potential for bugs which would not occur otherwise.

  2. You'll very likely run into more issues caused by filesystem incompatibility which are not strictly project problems, but still add unnecessary hassle under Windows. For example git falls apart when someone makes case-only filename changes on case-sensitive filesystems (ie. Linux) and other person pulls those changes to a Windows machine.

The real solution would be to develop in environment as similar to intended as possible. That means - on actual Linux host or in a Linux VM. This will guarantee that developers don't waste time (and money) on issues that exist only on their development platform. It will also guarantee that they don't miss problems which don't manifest on Windows.

Your customer doesn't care if the product runs well in a Linux VM on Windows. Your developers have to be familiar with Linux anyway because you're targeting Linux as your sole platform. Do you really want to spend resources on problems that don't exist in real-world scenarios?

gronostaj
  • 57,004
  • It's not really Windows. It's Docker-on-Linux-in-a-VM-on-Windows-with-not-completely-compatible-filesystem. That's not a reasonable production environment in my book. I understand that developers have their preferences, but they should also have common sense. (If that's still a non-answer for you, that's okay - it's just what I figured out after fighting with this issue for too long.) – gronostaj Aug 14 '19 at 16:24
  • This workaround is not for the application per se, rather it's for tooling around the environment. (running a git pre-commit hook - we run nodejs code in the hook and the problem is that the binaries installed by the linux containers can't be run by windows )
  • – dovidweisz Aug 14 '19 at 16:26
  • Oh, that's an important piece of information. Would it be an acceptable solution to run these binaries in another container? – gronostaj Aug 14 '19 at 16:29
  • 3
    I AM running them in another container.

    I just want to install the hook in this way for windows users. -- the hook starts the container :O

    – dovidweisz Aug 14 '19 at 16:32
  • I cannot downvote because of lacking of reputation but this answer is not convinced. "Linux-based Docker on Windows is a hack" is a fallacy. It supports Windows and it is worth to support it well. More and more developers are still using Windows for many reasons. – Han Apr 07 '20 at 02:17
  • Everything @Han said, plus: For dev purposes, sometimes you have a service running locally (localhost:3000 for example) and another in a container. On linux, container and host can access each other just by exposing the container's port (like -p 8080:8080), since localhost points to the same machine. With Docker running inside a VM, the mapped localhost:8080 is routed to the container/VM, but inside the container, localhost:3000 points to the VM instead of the host, since that isn't routed. (Fixable by replacing localhost with host's IP, so dynamic configs can come in handy). – blvz Apr 15 '20 at 06:14
  • @Han The point I'm trying to make is exactly "is it really worth to support Windows if your target platform is Linux". Docker architecture is significantly different on these OSes for technical reasons. If your team develops for Docker on Windows, you'll have to solve a bunch of problems that are Windows-specific (see comment by blvz above) and a handful of Linux-specific ones will surprise you (eg. more advanced permission model which is simplified if you share FS with Windows). These issues can be avoided by not developing for a platform which is not your target. – gronostaj Apr 15 '20 at 11:17
  • 2
    @gronostaj: I don't want to ague with you on this but see, we don't have to use linux to develop a linux software. "is it really worth to support Windows if your target platform is Linux" - yes it is, development environment is not always as powerful as deploy environment. And we can deploy docker on windows hosts, too. Just because people don't often do that doesn't mean that they don't do that at all. Back to the problem, docker is just a SW like other SW, it can easily get its running environment. We just want to know if somehow we can get that info from the docker or not. – Han Apr 16 '20 at 03:04
  • 2
    I agree with @Han: this is not useful. It does not answer the question at all. And yes there are plenty of real world scenarios, e.g. when developing for Linux and Windows at the same time or when your company has a policy that you must use Windows (please don't start discussing whether this is a good policy, because it isn't helping either). – Morty Jul 03 '20 at 07:14