How does Docker's use of the host OS guarantee cross-platform compatibility?

I understand that a key difference between VMs and Docker is that Docker uses the host operating system (OS), whereas VMs simulate a full OS, including their own kernel. Now, I’m confused about one point:

If earlier, without Docker, we used to install all packages and dependencies directly on our own OS, then how does Docker improve the situation? Specifically:

  • How does using the host OS in Docker containers guarantee that the application will run the same across different systems?

There is no guarantee, it is only more likely to run the same way as you don’t depend on already existing libraries and incompatibilities with your new applications requirements. And of course you can create the Docker image which contains all the libraries and run on other hosts. The kernel version, kernel modules and the hardware itself are still important and the app can depend on it. That is is when virtualization or a new bare metal server can help.

Not to mention security as you can hide most of the host from the app in the container.