tools icon indicating copy to clipboard operation
tools copied to clipboard

Getting No module named 'nf_core' after successfully building the docker image

Open ammarsabir15 opened this issue 3 years ago • 3 comments

Hi There,

I successfully built the docker image using the dockerfile given here (https://github.com/nf-core/tools/blob/master/Dockerfile) with slight modifications in the file given below

FROM python:3.8.9-slim 
LABEL authors="[email protected],[email protected]" \
description="Docker image containing requirements for the nfcore tools"

# Do not pick up python packages from $HOME
ENV PYTHONNUSERSITE=1

# Update pip to latest version
RUN python -m pip install --upgrade pip

# Install dependencies
COPY requirements.txt requirements.txt
RUN python -m pip install -r requirements.txt

# Install Nextflow dependencies
RUN apt-get update \
      && apt-get upgrade -y \
      && apt-get install -y git \
      && apt-get install -y wget

# Create man dir required for Java installation 
# and install Java
RUN mkdir -p /usr/share/man/man1 \
      && apt-get install -y  openjdk-11-jre \
      && apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Setup ARG for NXF_VER ENV
ARG NXF_VER=""
ENV NXF_VER ${NXF_VER}
# Install Nextflow
RUN wget https://github.com/nextflow-io/nextflow/releases/download/v21.04.3/nextflow  | bash \
      && mv nextflow /usr/local/bin \
      && chmod a+rx /usr/local/bin/nextflow
# Add the nf-core source files to the image
COPY . /usr/src/nf_core
WORKDIR /usr/src/nf_core

# Install nf-core
RUN python -m pip install .

# Set up entrypoint and cmd for easy docker usage
ENTRYPOINT [ "nf-core" ]
CMD [ "." ]

Instead of the curl I have just used the wget and tried to install the nextflow version 21.04.03. Although the Docker image is built successfully as shown below,

cheemaa@kepler:~/all_files/nextflow_docker$ cat logfile 
Sending build context to Docker daemon  98.82kB
Step 1/16 : FROM python:3.8.9-slim
 ---> 5904641efd27
Step 2/16 : LABEL authors="[email protected],[email protected]"       description="Docker image containing requirements for the nfcore tools"
 ---> Using cache
 ---> 2d43d8ba1cf3
Step 3/16 : ENV PYTHONNUSERSITE=1
 ---> Using cache
 ---> 682e6da6c52f
Step 4/16 : RUN python -m pip install --upgrade pip
 ---> Using cache
 ---> 64ac09a27790
Step 5/16 : COPY requirements.txt requirements.txt
 ---> Using cache
 ---> ea589aba8376
Step 6/16 : RUN python -m pip install -r requirements.txt
 ---> Using cache
 ---> da8e612968fa
Step 7/16 : RUN apt-get update       && apt-get upgrade -y       && apt-get install -y git       && apt-get install -y wget
 ---> Using cache
 ---> 0e4a8470273f
Step 8/16 : RUN mkdir -p /usr/share/man/man1       && apt-get install -y  openjdk-11-jre       && apt-get clean -y && rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> 0d7878e74239
Step 9/16 : ARG NXF_VER=""
 ---> Using cache
 ---> e174be554070
Step 10/16 : ENV NXF_VER ${NXF_VER}
 ---> Using cache
 ---> f54d7f1b655e
Step 11/16 : RUN wget https://github.com/nextflow-io/nextflow/releases/download/v21.04.3/nextflow  | bash       && mv nextflow /usr/local/bin       && chmod a+rx /usr/local/bin/nextflow
 ---> Using cache
 ---> dcecab0fccbe
Step 12/16 : COPY . /usr/src/nf_core
 ---> Using cache
 ---> 979b9af529f8
Step 13/16 : WORKDIR /usr/src/nf_core
 ---> Using cache
 ---> 968f059514c4
Step 14/16 : RUN python -m pip install .
 ---> Using cache
 ---> 6d42a11fcdbd
Step 15/16 : ENTRYPOINT [ "nf-core" ]
 ---> Using cache
 ---> 710284d3ef67
Step 16/16 : CMD [ "." ]
 ---> Using cache
 ---> 2433748d282b
Successfully built 2433748d282b
Successfully tagged nfcore/tools:latest
cheemaa@kepler:~/all_files/nextflow_docker$ 

But when I run the nextflow from the docker image I get following errror,

cheemaa@kepler:~/all_files/nextflow_docker$ docker run -it --rm -v /home/cheemaa/all_files/nextflow_docker:/home/cheemaa/all_files/nextflow_docker nfcore/tools:latest nextflow
Traceback (most recent call last):
  File "/usr/local/bin/nf-core", line 5, in <module>
    from nf_core.__main__ import run_nf_core
ModuleNotFoundError: No module named 'nf_core'

Is there any solution to this problem ?

Thanks,

ammarsabir15 avatar Mar 10 '22 21:03 ammarsabir15

Note to self, diff for the dockerfile changes:

diff --git a/original.dockerfile b/issue.dockerfile
index 8343e06c..49d485c6 100644
--- a/original.dockerfile
+++ b/issue.dockerfile
@@ -16,7 +16,7 @@ RUN python -m pip install -r requirements.txt
 RUN apt-get update \
       && apt-get upgrade -y \
       && apt-get install -y git \
-      && apt-get install -y curl
+      && apt-get install -y wget
 
 # Create man dir required for Java installation 
 # and install Java
@@ -28,7 +28,7 @@ RUN mkdir -p /usr/share/man/man1 \
 ARG NXF_VER=""
 ENV NXF_VER ${NXF_VER}
 # Install Nextflow
-RUN curl -s https://get.nextflow.io | bash \
+RUN wget https://github.com/nextflow-io/nextflow/releases/download/v21.04.3/nextflow  | bash \
       && mv nextflow /usr/local/bin \
       && chmod a+rx /usr/local/bin/nextflow
 # Add the nf-core source files to the image

ewels avatar Mar 15 '22 20:03 ewels

Instead of the curl I have just used the wget and tried to install the nextflow version 21.04.03.

@ammarsabircheema how come you're making these modifications? The dockerfile is already set up to allow you to use a specific version of Nextflow if you want (could be better commented / documented). The Nextflow installed listens to the $NXF_VER environment variable which is set with a Dockerfile ARG here. It's blank by default which should get the latest release, but you can customise by running Docker as follows:

docker build . --build-arg NXF_VER=21.04.3

Then you don't need to modify the Dockerfile at all.

Make sure that you're running in the base directory of the cloned nf-core/tools repo, as it expects the code to be in the current working directory:

# Add the nf-core source files to the image
COPY . /usr/src/nf_core
WORKDIR /usr/src/nf_core

This is my guess as to what's not working here, but it's a bit tricky to tell because most of your log output is just cached outputs 😉

Step 14/16 : RUN python -m pip install .
 ---> Using cache
 ---> 6d42a11fcdbd

Phil

ewels avatar Mar 15 '22 20:03 ewels

ps. Docs about Dockerfile ARG stuff: https://docs.docker.com/engine/reference/builder/#arg

ewels avatar Mar 15 '22 20:03 ewels

Closing as it seems solved, feel free to reopen if you still have problems :)

mirpedrol avatar Sep 22 '23 12:09 mirpedrol