0

My Dockerfile:

FROM node:10 AS builder
RUN npm install multi-file-swagger -g
WORKDIR /usr/src/app
COPY swagger/* ./
ARG API_HOST
ENV APP_HOST=$API_HOST
RUN sed -i 's+replace_host+'"$API_HOST"'+g' index.yaml
RUN multi-file-swagger index.yaml > index.json

FROM golang:1.12
WORKDIR /go/src/app
COPY . .
RUN go get -d -v ./...
RUN go install -v ./...
VOLUME /go/src/app
EXPOSE 8080
COPY --from=builder /usr/src/app/ swagger/
CMD ["app"]

My docker-compose.yml file:

version: '3.4'
services:
  myapp:
    build:
      context: .
      args:
        - API_HOST=api.my-real-domain.com
    volumes:
      - ./:/go/src/app
    ports:
      - "8080:8080"

If run docker build only:

docker build -t myapp . --build-arg API_HOST=api.my-real-domain.com

It can run the commands:

RUN sed -i 's+replace_host+'"$API_HOST"'+g' index.yaml
RUN multi-file-swagger index.yaml > index.json

And when lunch the container, I can find the index.json exists.

But if use docker-compose build and docker-compose up, then check the index.json in container, can't find it.

1 Answer 1

1

you overwrite all your files in app folder by using:

volumes:
  - ./:/go/src/app

you need to remove the volume section from your compose

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

1 Comment

The VOLUME in your Dockerfile isn't doing anything either and I'd strongly suggest removing it. (Its two most obvious effects will be preventing later RUN commands from working and leaking anonymous volumes when you docker run the container; it has no bearing on whether it's possible to hide the image contents like this or not.)

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.