Copy go package from previous stage based go image?

  docker, dockerfile, go, go-packages, python

In image based Python, I want to run one command (*) using go package gnostic:

RUN gnostic --grpc-out=test test/openapi/loyalty-bff.yaml

I did wrote following dockerfile:

FROM golang:1.17 AS golang
RUN go get -u github.com/google/[email protected]
RUN go get -u github.com/googleapis/[email protected]

FROM python:3.7.10
WORKDIR /app
ADD requirements.txt /app/
RUN pip install -r requirements.txt
ADD . /app/
COPY --from=golang /go/bin/gnostic /go/bin/gnostic-grpc
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]

I got error when run the command (*):

Command 'gnostic --grpc-out=loyalty-bff-1634180849463365375 loyalty-bff-1634180849463365375/loyalty-bff.yaml' returned non-zero exit status 127.

On the other hand, i can run when not use multi stages. Replace by install python in image based go, but building time is very long:

FROM golang:1.17
WORKDIR /app
RUN go get -u github.com/google/[email protected]
RUN go get -u github.com/googleapis/[email protected]
RUN apt-get update
RUN apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev wget libbz2-dev
RUN wget https://www.python.org/ftp/python/3.7.8/Python-3.7.8.tgz
RUN tar -xf Python-3.7.8.tgz
RUN cd Python-3.7.8 
    && ./configure --enable-shared 
    && make && make install
RUN apt-get install python3-pip -y

ADD requirements.txt /app/
RUN pip3 install -r requirements.txt
ADD . /app/
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]

Source: Docker Questions

LEAVE A COMMENT