Two containers – two Pythons – one site-packages?

Let’s assume I have two separate docker (or some other) containers which may only share folders with each other. There is a Python interpreter of the same version installed in both of these containers. Is there any way to make these interpreters to share almost the same PYTHONPATH, e.g. for both of them see all packages installed in any of these containers?

I know I can just import packages from a folder, but I want do find out if it’s possible to do such steps:

  • Open port between docker containers
  • How to use --init parameter in docker run
  • Disable access to LAN from docker container
  • Cannot ssh to server as I install on OVH dedicated server
  • How docker container has extra memory than the host OS?
  • java Runtime.getRuntime().availableProcessors() and nproc return different values
    1. Install package A in first container with pip or easy_install. This package may depend on other packages, which are located in second container and somehow mounted to first one. Also, there are some possible dependencies (which second container is missing) which will be installed into first container.
    2. Inside second container import package A from first container without issues, so it should see both dependencies located in first and second containers.

    The thing is, I’m trying to use stevedore to look for packages by entry points, but they should be installed and, possibly, upgraded independently from what’s installed in second container.

  • How to use host network while linking to a container?
  • Celery tasks for different python app in different Docker containers
  • docker-machine command fails on openstack
  • Running Django in docker-compose
  • redirect the output of docker-exec
  • Boot2docker VM graphics
  • 2 Solutions collect form web for “Two containers – two Pythons – one site-packages?”

    I do not know if I understood the question. If this does not answer your question, could you comment? To me there were like three questions you asked:

    1. import behavior (I answered below)
    2. Updating packages
    3. stevedore – optional or not, a try or a requirement?

    Import Behavior

    There is a list called sys.path. It is the list of folders in which python looks for packages.
    Suppose you have folder1 and folder2 in this list.

      +----- module_a
      +----- module_b
      +----- module_a
      +----- module_c

    A Python process with ['folder1', 'folder2', ...] as sys.path would do that:

    import module_a # from folder1
    import module_b # from folder1
    import module_c # from folder2

    A Python process with ['folder2', 'folder1', ...] as sys.path would do that:

    import module_a # from folder2 # difference
    import module_b # from folder1
    import module_c # from folder2

    This is how I understand the Python import behavior. I do not use docker or PYTHONPATH, so I can not refer to that.

    You could have a container whose entry point creates a virtualenv in a volume and installs all the dependencies defined in a requirements file. Then you could use the –volumes-from flag to mount the virtual env in other containers and execute the activate script to import the environment..

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.