无法将本地目录从docker-compose文件挂载到容器中

时间:2020-03-29 11:50:49

标签: docker docker-compose docker-volume

我想在使用COPY命令之前将项目的本地目录挂载到docker容器上,但是当我进行更改时,我必须重新构建那些涉及从bash脚本进行某些安装的部分。

这是我的docker-compose文件

version "3.7"
services
 tesseract:
    container_name: tesseract
    build:
      context: ./app/services/tesseract/
      dockerfile: Dockerfile
    volumes:
      - ./app/services/tesseract:/tesseract/

构建时没有任何错误,运行容器时WORKDIR tesseract为空

这是我的Dockerfile

FROM ubuntu:19.10

ENV DEBIAN_FRONTEND=noninteractive
ENV TESSERACT=/usr/share/tesseract

WORKDIR /tesseract

RUN apt-get update && apt-get install -y \
    build-essential \
    software-properties-common \
    python3.7 \
    python3-pip \
    cmake \
    autoconf \
    automake \
    libtool \
    pkg-config \
    libpng-dev \
    tesseract-ocr \
    libtesseract-dev \
    libpango1.0-dev \
    libicu-dev \
    libcairo2-dev \
    libjpeg8-dev \
    zlib1g-dev \
    libtiff5-dev \
    wget \
    git \
    g++ \
    vim

RUN git clone https://github.com/tesseract-ocr/tesseract $TESSERACT

COPY . /tesseract/
RUN chmod +x scripts/*
RUN scripts/compile_tesseract.sh
RUN scripts/langdata_lstm.sh scripts/start.sh
RUN pip3 install -r requirements.txt

ENV TESSDATA_PREFIX=/usr/share/tesseract/tessdata

1 个答案:

答案 0 :(得分:1)

docker卷的主要目标是

卷是持久化由Docker容器生成和使用的数据的首选机制。

表示卷用于在容器的生命周期之外保留数据。如果要将文件或目录COPY放入容器中,请使用COPY指令。

如果要将本地文件复制到Docker映像,请始终使用COPY,因为它更明确。

借助Docker-compose,您可以使用绑定挂载卷

https://docs.docker.com/compose/gettingstarted/#step-5-edit-the-compose-file-to-add-a-bind-mount#step-5-edit-the-compose-file-to-add-a-bind-mount

相关问题