JohnK
JohnK

Reputation: 55

Requirements.txt not installed in Docker container

I have got the following Dockerfile

FROM jupyter/scipy-notebook

COPY . ./work

COPY setup.py /work

RUN pip install --upgrade pip && pip install -e .

RUN pip install -r ./work/requirements.txt

COPY src /work/src

WORKDIR /work

and the following docker-compose.yml

version: '3.7'

networks:
  ling172:

services:
   jupyter:
      
      image: jupyter/datascience-notebook:r-4.0.3
      environment:
        - JUPYTER_TOKEN=password
        - JUPYTER_ENABLE_LAB=yes

      volumes:
        - .:/home/jovyan/work
        - ./notebooks:/home/jovyan/work
        - ./src:/home/jovyan/work
      ports:
        - 7777:8888
      container_name: almond_analysis
      networks:
        - ling172

and the following requirements.txt file

openpyxl==3.0.10

The project structure is

almond_analysis:
    notebooks:
        data_exploration.ipynb
    src:
       __init__.py
       plots.py
    .gitignore
    docker-compose.yml
    Dockerfile
    README.md
    requirements.txt
    setup.py

and the setup file is

from setuptools import find_packages, setup
import sys
import os

sys.path.insert(0, os.path.abspath( os.path.dirname(__file__)))


requirements_path="requirements.txt"
with open(requirements_path) as requirements_file:
    requirements = requirements_file.read().splitlines()

setup(
    name="almond_analysis",
    version="0.0.1",
    description = "Almond analysis",
    long_description="Analysing yield with Python.",
    author= "George N",
    packages= find_packages(),
    install_requires=requirements,
    classifiers=[
        "Programming Language :: Python :: 3"
    ],
    python_requires =">= 3.0.*",
)

The problem is that once I open the data_exploration.ipynb notebook the openpyxl package has not been installed, which means that the requirements.txt file has not been read. I suspect that this is because I am starting the container with the command docker compose up -d which means that I am not rebuilding the image, which means that the Dockerfile is not read. So I modified the docker-compose.yml file as follows (ie I added build: .)

version: '3.7'

networks:
  ling172:

services:
   jupyter:
      build: .
      image: jupyter/datascience-notebook:r-4.0.3
      environment:
        - JUPYTER_TOKEN=password
        - JUPYTER_ENABLE_LAB=yes

      volumes:
        - .:/home/jovyan/work
        - ./notebooks:/home/jovyan/work
        - ./src:/home/jovyan/work
      ports:
        - 7777:8888
      container_name: almond_analysis
      networks:
        - ling172

but without luck.

Does anyone know how to install, successfully, the packages in requirements.txt?

Upvotes: 0

Views: 1942

Answers (1)

JohnK
JohnK

Reputation: 55

Solved by typing docker-compose up -d --build with the second docker-compose.yml file and all other files as shown in the question (as suggested by @dallyger).

Upvotes: 2

Related Questions