I’m maintaining a Docker image of a database (Linux). The image runs on Linux and Windows (Linux container on Windows – lcow). But on Windows it behaves a bit different.
How can I detect if the host OS is Windows from inside the container?
I’m maintaining a Docker image of a database (Linux). The image runs on Linux and Windows (Linux container on Windows – lcow). But on Windows it behaves a bit different.
How can I detect if the host OS is Windows from inside the container?
2
Answers
Docker exposes certain environment variables to each container that can provide information about the host. You can try checking the OSTYPE environment variable, which might provide information about the host operating system.
Here’s an example command that you could use within a Linux container to check the host’s OSTYPE:
You cannot check the host OS from inside the container.
As workaround, I suggest to think in the opposite way and, so, to add an environmental variable inside the Dockerfile, such as:
and then set it through the build command with
--build-arg
options:Then, according to the value of the variable you can differenciate the behavior of the container or of the image you’re building.