title: Docker - pip install all requirements.txt files in shared volume on docker.compose up
body: <p>I am trying to use docker-compose to share python modules with other containers ensuring these containers all have 100% of the requirements.txt files pip installed.</p>
  
  <p>I have been able to use volumes to share the the shared python modules with the other containers (at /src/shared-modules). However I'm struggling to automate the 'pip installing' of all the requirements.txt files found within /src/shared-modules.</p>
  
  <p>The Dockerfile looks like this:</p>
  
  <pre><code>FROM python:3.6.5
  
  COPY . /src
  
  **#Run pip install on all found requirements.txt files in the container**
  RUN for req in `find . -name requirements.txt -type f`; do pip install --trusted-host pypi.org -r $req; done
  
  WORKDIR /src
  </code></pre>
  
  <p>This works for everything in the host folder copied to the container but doesn't work for anything in the /src/shared-modules folders. Maybe they don't exist yet at the time the pip install command is run in the dockerfile or maybe they haven't been linked to the source shared-modules container yet?</p>
  
  <p>The docker-compose.yaml looks like this:</p>
  
  <pre><code>  db:
      image: tutum/mongodb
  
    shared-modules:
      build: ./shared-modules
      volumes:
        - "shared-modules:/src/shared-modules"
  
    web:
      build: ./django-site
      entrypoint: "python manage.py runserver 0.0.0.0:8000"
      volumes:
        - "shared-modules:/src/shared-modules"
  
  
  volumes:
    shared-modules:
  </code></pre>
  
  <p>I have tried to add the pip install to the entrypoint + command commands in the docker-compose-yaml file which looks like this:</p>
  
  <pre><code>  web:
      build: ./django-site
      entrypoint: /bin/bash
      command: "for req in `find /src/shared-modules -name requirements.txt -type f`; do pip install --trusted-host pypi.org -r $req; done &amp;&amp; python manage.py runserver 0.0.0.0:8000"
      volumes:
        - "shared-modules:/src/shared-modules"
  </code></pre>
  
  <p>I hoped that this would run the command on an already created container, already linked to the shared-modules container but the requriemtns.txt files of the /src/shared-modules were not installed on docker-compose up.</p>
  
  <p>The </p>
  
  <blockquote>
    <p>for req in <code>find . -name requirements.txt -type f</code>; do pip install
    --trusted-host pypi.org -r $req; done</p>
  </blockquote>
  
  <p>command works but only if I attach to the running container after its creation  and manually do it. I would really like to automate that as part of the docker-compose up process.</p>
  
  <p><strong>How can I execute a bash command on a container after the volume is assigned as part of the docker-compose up process?</strong></p>
  
  <p><strong>Is there a better way to do this?</strong></p>