I am new to docker and this is just a fascinating tool. However, I can't understand one thing about it. Simple Dockerfile usually begins with OS name and version, like:
FROM ubuntu:xenial
....
But which Linux OS will be used for Dockerfile like
FROM perl
....
or
FROM python:3.6
....
Of course I can find this out by running a container from this image and printing out the OS info, like:
docker run -it --rm perl bash
# cat /etc/*-release
or
docker run -it --rm python:3.6 bash
# cat /etc/*-release
BTW, In both cases the OS is "Debian GNU/Linux 10 (buster)".
So, my questions are:
How do I find out which OS will be run for a specific docker image without actually creating a docker container from it (the docker inspect
command does not provide this info: docker inspect perl | grep -i Debian
)
How do I change the OS type for existing docker image. For example, I have an image that uses Ubuntu 14.04, and I want to change it to Ubuntu 18.04.
A docker image doesn't need an OS. There's a possibility of extending the scratch image which is purposely empty and the container may only contain one binary or some volume.
Having an entire OS is possible but also misleading: The host shares its kernel with the container. (This is not a virtual machine.)
That means that no matter what "OS" you are running, the same kernel in the container is found:
Both:
docker run --rm -it python:3.6 uname -a
docker run --rm -it python:3.6-alpine uname -a
will report the same kernel of your host machine.
So you have to look into different ways:
docker run --rm -it python:3.6 cat /etc/os-release
or
lsb_release -sirc
or for Cent OS:
cat /etc/issue
Instead of scratch, a lot of images are also alpine-based, to avoid the size overhead. An Ubuntu base image can easily have 500MB fingerprint whereas alpine uses around 5MB; so I'd rather check for that as well.
Also avoid the trap of manually installing everything onto one Ubuntu image inside one big Dockerfile. Docker works best if each service is its own container that you link together. (For that, check out docker-compose
.)
In the end, you, as a user, shouldn't care about the OS of an image, but rather its size. Only as a developer of the Dockerfile is it relevant to know the OS and that you'll find out either by looking into the Dockerfile the image was built (if it's on docker hub you can read it there).
You basically have to look what was used to create your image and use the appropriate tools for the job. (Debian-based images use apt-get
, alpine uses apk
, and Fedora uses yum
.)