Can docker image choose the OS?

Viewed 6416

Can a Docker image specify which operating system it can use? Say one Image with Windows and another with RHEL? In this case how Docker will maintain two different operating systems?

2 Answers

Docker is composed of layers. At the beginning of any Dockerfile you specify the OS by typing e.g. FROM python:3 My belief is that if you were to add another OS. The image would retain the environment from the first OS and install the env of the second OS over that. So essentially, your image would have both environments.

If you create a python image from the command above and name it docker build -t 'this_python' . then make a new Dockerfile with the first line: FROM this_python so the new image has python already, and you can install anything over this.

Best practice is to keep your docker image as small as possible. Install only what is required.

A quick example

FROM python:3
FROM ubuntu:latest

RUN apt-get update

The above Dockerfile gives you an image with Python and Ubuntu installed. But this is not how you should do it. Better is to use FROM ubuntu:latest and then install python over it.

Docker image is just docker image. It doesn't depend on the OS on which you run the docker engine. For example, when you run your docker image on Windows, actually it run on docker engine, which was hosted by a Virtual host of linux.

Related