簡體   English   中英

無法從 docker-compose 文件將本地目錄掛載到容器中

[英]Cannot mount local directory into container from docker-compose file

我想在使用 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

docker volume 的主要目標是

卷是持久化 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM