简体   繁体   中英

Where does docker install dependencies?

This is a beginner question but I started learning about docker and how each container is isolated from another container.

In an example in the lesson, the video said that the great thing about docker is that we can ignore dependency conflicts so if we have image A that requires dependency A v1.0 and image B that requires dependency A v2.0 , then it's as simple as specifying it in the docker image and we don't have to worry about conflicts about versions and whatnot.

Now my questions are:

  1. When I run a docker container, where are those dependencies installed? If, for example, my host machine doesn't have dependency A , then when I run a docker container that require it, where does it install it to run the container?

  2. If it gets installed, is it isolated to that docker container only? If I wanted to use dependency A on my host machine, would I be able to from the installed version from the docker container or do I have to install it again on my host machine?

  3. Is the dependency installed multiple times per docker container? If I have 5 running containers of image A and 10 containers of image B , it doesn't install dependency A v1.0 5 times and dependency A v2.0 10 times, right?

When I run a docker container, where are those dependencies installed? If, for example, my host machine doesn't have dependency A, then when I run a docker container that require it, where does it install it to run the container?

The software installed on your host machine has no relation to the software running inside the container. A container is running in an isolated filesystem environment and does not have access to your host. If a package running in a container has a dependency, that dependency is installed when the image is built , not when the container runs, and the dependencies are installed into the image along with anything being installed explicitly.

If it gets installed, is it isolated to that docker container only? If I wanted to use dependency A on my host machine, would I be able to from the installed version from the docker container or do I have to install it again on my host machine?

As above, your containers are isolated from your host. Software on your host will not be able to make use of a dependency installed in a container.

Is the dependency installed multiple times per docker container? If I have 5 running containers of image A and 10 containers of image B, it doesn't install dependency A v1.0 5 times and dependency A v2.0 10 times, right?

Nothing is "installed" when you run a container, other than the necessary Docker image if it wasn't already available on your host. That is, when you docker run <something> ... :

  • Docker will pull the necessary image, if it doesn't already exist, and then
  • Docker will start a container from that image.

Any software installation happened when the image was built.

If you have 5 running containers of image A, you still only have one copy of the underlying image installed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM