我的Dockerfile遇到问题并设置了正确的工作目录

时间:2020-05-14 00:08:31

标签: docker pytorch

这是我的第一个Dockerfile,这是我到目前为止所拥有的。

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"]

但是当我尝试运行docker映像时,找不到数据文件夹内的文件。 这是我的项目结构的图片。 enter image description here

将其更改为建议的内容,但仍然出现错误。

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"]

这是错误消息。

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 个答案:

答案 0 :(得分:0)

我相信您的Dockerfile中缺少COPY data/ /data/命令。您仅在复制src文件夹,而不在复制数据。请在Dockerfile中的COPY src / / src /行之后添加COPY data /data/,然后尝试一下。