I am very interested in docker and I’ve read about it but I’m a bit confused with containers. When we pull for instance, the official nginx from docker hub, is it only the application or nginx comes with operating system? It seems to me that all containers come with the operating system since with docker exec -it app-name bash i can enter and make updates or install packages. This part is confusing to me because I had the idea that it was only the application and nothing else.
2 Solutions collect form web for “Docker confusion”
It depends. Most software needs some parts of the operating system to run (which can be some libraries, or utilities); in those cases, a “base” operating system is used (
Alpine for the official images), so that the application can run. Although you’re able to
docker exec into such a container and start a bash/shell session, this should only be used for debugging; in general the container (
nginx) should be considered as the application nginx, not as a “virtual machine with nginx installed”.
Some software is statically linked and doesn’t need additional things to be installed. For example, the hello-world or the traefik image do not use an operating system as a base, and only contain a single binary, nothing else.
It depends of what you call the “OS”. Is you mean both
kernel space and
user space – answer is no. Containers change user space only.
Docker works like chroot or lxc, it uses single Linux kernel from host and binaries/libraries/etc in containers to run, containers in nutshell are isolated namespaces on single machine.
So, “OS” will never change in case if containers, but
"environmnet" will change (libc, shells, all that stuff).
Also, check this wiki article about cgroups.
PS: sure, when you’re not on Linux you need to install VM with Linux to use Docker. But this is another question.