0

возникла необходимость подключить python модуль(функцию из файла) из другого Docker контейнера,сколько бьюсь, не могу понять как это сделать и вообще возможно ли)

Папки проекта

Папки проекта

Docker compose:

version: "3.7"

services:

  flask:
    build: ./flask
    container_name: flask
    restart: always
    environment:
      - APP_NAME=MyFlaskApp
    expose:
      - 8080
    volumes:
      - "/home/nikita/app/telegram_bot"

  telegram_bot:
    build: ./telegram_bot
    container_name: telegram_bot
    restart: always

  nginx:
    build: ./nginx
    container_name: nginx
    restart: always
    ports:
      - "80:80"

Docker файл из flask:

FROM python:3.8

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app 
ADD . /app

# Install the dependencies
RUN pip install -r requirements.txt

# run the command to start uWSGI
CMD ["uwsgi", "app.ini"]

Docker файл из telegram_bot:

FROM python:3.8

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app 
ADD . /app

# Install the dependencies
RUN pip install -r requirements.txt

# run the command to start uWSGI
CMD ["python", "./main_bot.py"]

Задача подгрузить функцию из main_bot.py, во flask.

1 ответ 1

1
services:

  flask:
    build: ./flask
    container_name: flask
    restart: always
    environment:
      - APP_NAME=MyFlaskApp
    expose:
      - 8080
    volumes:
      - /home/nikita/app/telegram_bot:/app/telegram_bot

по идее после этого в контейнере фласка main_bot.py будет доступен по пути /app/telegram_bot/main_bot.py

1
  • Спасибо! Помогло)
    – Froot
    18 ноя 2020 в 11:03

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.