Having trouble with my Dockerfile and setting correct working directory

Viewed 74

This is my first Dockerfile and this is what I have so far.

FROM python:3.6-stretch


# install build utilities
RUN apt-get update && \
    apt-get install -y gcc make apt-transport-https ca-certificates build-essential

# check our python environment
RUN python3 --version
RUN pip3 --version

# set the working directory for containers
WORKDIR  /usr/src/toxic-content-monitoring

# Installing python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy all the files from the project’s root to the working directory
COPY src/ /src/
RUN ls -la /src/*

# Running Python Application
CMD ["python3", "/src/main.py"]

But when I am trying to run the docker image the files inside the data folder cannot be found. Here is a picture of the my project structure. enter image description here

Changed it to what was suggested and still getting an error.

FROM python:3.6-stretch

# install build utilities
RUN apt-get update && \
    apt-get install -y gcc make apt-transport-https ca-certificates build-essential

# check our python environment
RUN python3 --version
RUN pip3 --version

# set the working directory for containers
WORKDIR  /usr/src/toxic-content-monitoring

# Installing python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy all the files from the project’s root to the working directory
COPY src/ /src/
COPY data /data/
RUN ls -la /src/*

# Running Python Application
CMD ["python3", "/src/main.py"]

This is the error message.

docker run toxic-content-monitoring:0.1
wiki.en.vec: 6.60GB [10:05, 10.9MB/s]                                
  0%|          | 0/2519371 [00:00<?, ?it/s]Skipping token 2519370 with 1-dimensional vector ['300']; likely a header
100%|██████████| 2519371/2519371 [08:36<00:00, 4878.67it/s]
Traceback (most recent call last):
  File "/src/main.py", line 11, in <module>
    from preprocessor import normalize_comment, clean_text
  File "/src/preprocessor.py", line 42, in <module>
    word_file = open(link, "r")
FileNotFoundError: [Errno 2] No such file or directory: 'data/identity_hateWordFile.txt'
1 Answers

I believe your Dockerfile is missing COPY data/ /data/ command in it. You are only doing a copy of src folder and not data. Please include COPY data /data/ right after COPY src/ /src/ line in your Dockerfile and give it a try.

Related