2

I have below Dockerfile"

FROM openjdk:12.0.2

EXPOSE 8080

ADD ./build/libs/*.jar app.jar

ENTRYPOINT ["java","-jar","/app.jar"]

The resulting Docker image encapsulates Java program. When I deploy this Docker image to Windows Server or Linux, does the image always include OS like Linux which runs on top of host OS (Windows Server or Linux) ?

I am asking this question in the sense of Docker image being physical box which contains other boxes (one being openjdk), does this box also contain Linux OS box that I can pull out of it ( assuming if this was possible) and install it as Linux OS on empty machine?

ace
  • 11,526
  • 39
  • 113
  • 193
  • 3
    seems easily answered by official docs or an SO FAQ like [Docker, what is it and what is the purpose](https://stackoverflow.com/questions/28089344/docker-what-is-it-and-what-is-the-purpose) – underscore_d Sep 01 '20 at 12:02

3 Answers3

2

That depends on what you call the "OS". It will always contain stuff from the distribution image, it is built on.
For example, a debian based images will include apt and other debian-specific tools. But most of the stuff you need on a "complete" machine (as in non-container), will have been removed to keep the image as small as possible.

It will not contain the kernel, as it is running on the host machine and is controlled by the host's kernel.

toydarian
  • 4,246
  • 5
  • 23
  • 35
  • 2
    Technically speaking you can use `FROM scratch` to create image not containing anything other than what you `COPY` or `ADD` to it. – Konrad Botor Sep 01 '20 at 12:06
1

It doesn't include the entire operating system, but the image will be dependent on either linux or windows, you can't build an image that runs on both in one Dockerfile. The reason for the dependency is that a docker container shares resources with it's host machine in a carefully fenced off way, this mechanism is different on windows and linux (though to you, as a docker user, the difference is invisible).

Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62
Ceilingfish
  • 5,397
  • 4
  • 44
  • 71
  • I'm pretty sure that the whole point with docker is that you can run the image on all platforms. The FROM directive in the Dockerfile only declares which OS the script in the Dockerfile is based on. When the container runs, Docker will make it work on any host. – Quentin Hayot Sep 01 '20 at 12:07
  • You can indeed make code work on different platforms, however docker images originate from either windows or *nix images, which cannot be run on the same host machine. You _could_ provide a [build argument to dynamically control which source image your image is based on](https://www.jeffgeerling.com/blog/2017/use-arg-dockerfile-dynamic-image-specification), but that's going to make things tricky when it comes to knowing which commands are available for `SHELL` or `CMD` directives. – Ceilingfish Sep 01 '20 at 12:14
  • Thanks, I now realize that I never actually had to run a *nix container on Windows. Thanks for the enlightening. Please make a small edit to your answer so I can revoke my downvote – Quentin Hayot Sep 01 '20 at 12:18
1

The "official" OpenJDK images from the Docker Hub are available in variants based on a number of different Linux distributions. There is a cut-down Debian, an Alpine, and others. There are advantages and disadvantages to each.

The image will need to contain enough operating system dependencies to allow the JVM to run. It may also include basic diagnostic and management tools -- enough to carry out rudimentary troubleshooting in the container, anyway. You can expect all the images to contain at least basic console shell tools like "cp" and "cat", although they differ in implementation. For example, the Alpine variant gets these utilities from BusyBox, not from a conventional GNU/Linux installation.

It's possible to create a Docker image that contains no platform dependencies at all, but there's little incentive to be that minimal -- you'd just have to build more stuff into the application program itself.

Kevin Boone
  • 4,092
  • 1
  • 11
  • 15