0

I want to mount the local directory of a project to docker container before I used COPY command but when I make changes I have to rebuild those parts which involve some installation from bash scripts.

This is my docker-compose file

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

I don't have any errors when building and my WORKDIR tesseract is empty when i run container

This is my 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 Answer 1

1

Main objective of docker volume is

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers.

which means volumes are used to persist the data outside the lifecycle of a container. If you want to COPY a file or a directory into a container, please use COPY instruction.

If you’re copying in local files to your Docker image, always use COPY because it’s more explicit.

With Docker-compose, you can use a bind mount volume

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the explanation, i didn't like the thing when i make changes inside service directory it rebuilds that part of the container and it involves installing dependencies
Can you add your Dockerfile? Maybe we can do some optimizations in that.
by the way, i found out from getting started guide that you can mount local directory so you don't need o rebuild container from here docs.docker.com/compose/gettingstarted/… Edited my question
With docker-compose, you can use a bind mount option. Regarding Docker file, ideally, you should install your dependencies in the initial stage of the image and then copy the rest of the code. ``` COPY requirements.txt /tesseract/ RUN pip3 install -r requirements.txt COPY . /tesseract/ ``` This will save a lot of time while building the image as it will pick up the dependencies from the cache layer
Can you please check the answer and accept it if it solves the answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.