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

标签 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'

最佳答案

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

关于docker - 我的Dockerfile遇到问题并设置了正确的工作目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61787013/

相关文章:

由于 "volume store metadata database: timeout"导致 Docker 无法启动

docker - 使JMX与Spotify/Kafka Docker镜像一起使用

amazon-web-services - AWS Codebuild没有传递环境变量?

python - 评估pytorch模型: `with torch.no_grad` vs `model.eval()`

python - 为什么 PyTorch 自定义模块中需要 super 构造函数?

bash - Dockerfile 找不到入口点脚本

mysql - Spring 启动 mysql docker windows 7

pytorch - 具有相同输入的相同预训练模型,运行多次会给出不同的输出

python - 管道异常 : No mask_token ([MASK]) found on the input

list - pytorch中有类似 'TensorList’的东西吗?