0

Hey all im currently building an web application based on flask/mariadb/nginx and so on. Im currently wondering if you guys know of a way to use the python packages i have installed on my local dev machine.

Currently all is done via the regular requirements.txt in my Dockerfile.

Here is my Compose file:

version: '3'
services:
  backendserver:
    build:
      context: ./backendServer
      #dockerfile: ./backendServer/Dockerfile
    ports:
     - "5000:5000"
    networks:
      - db_network

  db:
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: DB_PW
      MYSQL_USER: DB_USER
      MYSQL_DATABASE: DB_NAME
    volumes:
      - ./shared-files:/var/lib/mysql
    networks:
      - db_network
    ports:
      - "3306:3306"
  pabs_ss:
    restart: always
    env_file: .env
    build: .

    volumes:
      - ./shared-files:/shared-files
    ports:
      - "5005:5005"
    networks:
      - db_network
      - web_network
  nginx:
    restart: always
    image: "nginx:latest"
    ports:
      - "85:85"
    volumes:
      - ./nginx:/etc/nginx/conf.d
    networks:
      - web_network
    depends_on: 
      - pabs_ss
networks:
  db_network:
    driver: bridge
  web_network:
    driver: bridge

Here is my Dockerfile:

FROM python:3.6

ENV FLASK_APP run.py

COPY run.py gunicorn-cfg.py requirements.txt config.py .env ./
COPY app app
#COPY shared-files/db.sqlite3 /

RUN pip install -r requirements.txt


EXPOSE 5005 8080
CMD ["gunicorn", "--config", "gunicorn-cfg.py", "run:app"]

As you can see im currently using the "normal" way of doing, though im growing quite tired of basically downloading everything everytime.

So any idea of how i can use the python packages from my local machine in the container?

Thanks and advance and so long :)

  • Creating a local package server is very simple. Just download all the wheels and create a simple folder structure that will serve as your package server. This will avoid downloading again and again. (Refer packaging.python.org/guides/hosting-your-own-index.) – Nishant Mar 16 '21 at 08:05
  • maybe you'd better just reorganize dockerfile so the builder would use caching? :shrug: – NobbyNobbs Mar 16 '21 at 08:38
  • The linked question has three answers, all of which are good ones: run `pip install` before installing your application so it doesn't get repeated; use a fairly new Docker feature to cache the downloaded packages; or use a bind mount to keep the packages outside the container (I'd avoid this last option though). – David Maze Mar 16 '21 at 10:55
  • Hey all thanks for the replys, i think i will, in the mid to long term, setup my own package index. – Zeto_oh_well Mar 17 '21 at 14:16

0 Answers0