From 6f198b038e4f29e046cd23eb4525116dc70e73d7 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Aug 2021 17:08:54 +0800 Subject: [PATCH 1/2] Modify Dockerfile, the modified image size is about 9M. --- Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index c31a96d..0f58db4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ -FROM debian:bullseye-slim +FROM debian:bullseye-slim AS build LABEL maintainer="otiai10 " -ARG LOAD_LANG=jpn - RUN apt update \ && apt install -y \ ca-certificates \ @@ -11,6 +9,7 @@ RUN apt update \ golang=2:1.15~1 ENV GO111MODULE=on +ENV GOPROXY="https://goproxy.cn,direct" ENV GOPATH=${HOME}/go ENV PATH=${PATH}:${GOPATH}/bin @@ -19,7 +18,12 @@ WORKDIR $GOPATH/src/github.com/otiai10/ocrserver RUN go get -v ./... && go install . # Load languages +ARG LOAD_LANG=chi-sim RUN if [ -n "${LOAD_LANG}" ]; then apt-get install -y tesseract-ocr-${LOAD_LANG}; fi ENV PORT=8080 -CMD ["ocrserver"] + +FROM scratch AS OS + +COPY --from=build /go/bin/ocrserver / +CMD [ "/ocrserver" ] \ No newline at end of file From dd4fa05b3723a385ac1784414d78d8639b99c644 Mon Sep 17 00:00:00 2001 From: RocSun <710989028@qq.com> Date: Thu, 5 Aug 2021 16:09:27 +0800 Subject: [PATCH 2/2] fix docker image error. test pass. --- Dockerfile | 79 ++++++++++++++++++++++++++++++++++++---------- docker-compose.yml | 12 +++++-- 2 files changed, 71 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0f58db4..1561982 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,74 @@ -FROM debian:bullseye-slim AS build -LABEL maintainer="otiai10 " +# make base image. +FROM debian:bullseye-slim AS base +LABEL maintainer="otiai10 " \ + updatedBy="RocSun " -RUN apt update \ - && apt install -y \ - ca-certificates \ - libtesseract-dev=4.1.1-2.1 \ - tesseract-ocr=4.1.1-2.1 \ - golang=2:1.15~1 +RUN apt-get update \ + && apt-get install -y ca-certificates \ + apt-transport-https \ + # this setting local apt mirrors + && cp -a /etc/apt/sources.list /etc/apt/sources.list.bak \ + && sed -i "s@http://deb.debian.org@https://repo.huaweicloud.com@g" /etc/apt/sources.list \ + && sed -i "s@http://security.debian.org@https://repo.huaweicloud.com@g" /etc/apt/sources.list \ + && apt-get update \ + && apt-get install -y libtesseract-dev=4.1.1-2.1 \ + tesseract-ocr=4.1.1-2.1 + +# build source. +FROM base AS build + +RUN apt install -y golang=2:1.15~1 ENV GO111MODULE=on ENV GOPROXY="https://goproxy.cn,direct" -ENV GOPATH=${HOME}/go +ENV GOPATH=/go ENV PATH=${PATH}:${GOPATH}/bin -ADD . $GOPATH/src/github.com/otiai10/ocrserver -WORKDIR $GOPATH/src/github.com/otiai10/ocrserver +ADD . $GOPATH/src/ocrserver +WORKDIR $GOPATH/src/ocrserver RUN go get -v ./... && go install . -# Load languages +# make run env. This is build image. +FROM base AS OS +ENV PORT=8080 +COPY --from=build /go /go + ARG LOAD_LANG=chi-sim -RUN if [ -n "${LOAD_LANG}" ]; then apt-get install -y tesseract-ocr-${LOAD_LANG}; fi +RUN if [ -n "${LOAD_LANG}" ]; then apt-get install -y tesseract-ocr-${LOAD_LANG}; fi \ + && apt-get clean +CMD [ "/go/bin/ocrserver" ] -ENV PORT=8080 +# ################################################################################ +# # debian:bullseye-slim image size of is about 220M. # +# # if use alpine. image size of is about 160M. Here's the alpine-based code # +# # min image in dockerhub rocsun/ocr-server # +# ################################################################################ + +# FROM alpine:3.14 as base +#LABEL maintainer="otiai10 " \ +# updatedBy="RocSun " + +# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \ +# && apk add tesseract-ocr \ +# && apk add tesseract-ocr-dev \ +# && apk add tesseract-ocr-data-chi_sim + +# FROM base AS build + +# RUN apk add go \ +# g++ + +# ENV GO111MODULE=on +# ENV GOPROXY="https://goproxy.cn,direct" +# ENV GOPATH=/go +# ENV PATH=${PATH}:${GOPATH}/bin -FROM scratch AS OS +# ADD . $GOPATH/src/ocrserver +# WORKDIR $GOPATH/src/ocrserver +# RUN go get -v ./... && go install . -COPY --from=build /go/bin/ocrserver / -CMD [ "/ocrserver" ] \ No newline at end of file +# FROM base AS OS +# RUN apk add bash +# COPY --from=build /go /go +# ENV PORT=8080 +# CMD ["/go/bin/ocrserver"] diff --git a/docker-compose.yml b/docker-compose.yml index e0e558a..aff107e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,16 @@ version: "3.7" services: - web: - build: + ocr-web: + build: context: . - # dockerfile: Dockerfile + dockerfile: Dockerfile ports: - "8080:8080" environment: PORT: 8080 + # container_name: ocr-server + # command: + # - /bin/bash + # - -c + # - | + # /go/bin/ocrserver \ No newline at end of file