如何等待命令在容器内完成执行

时间:2018-07-06 17:09:57

标签: bash shell docker dockerfile grafana

使用以下dockerfile:

FROM golang:1.9 AS build-go
RUN go get github.com/grafana/grafana; exit 0
WORKDIR $GOPATH/src/github.com/grafana/grafana
RUN go run build.go setup
RUN go run build.go build

FROM node:8 AS build-node
COPY --from=build-go $HOME/go/src/github.com/grafana/grafana .
RUN npm install -g yarn
RUN yarn install --pure-lockfile
CMD npm run watch
EXPOSE 3000

我创建并镜像,然后通过bash文件将其用于启动容器:

docker run -d -P --name=grafanabuildfromsrc myimg
docker exec grafanabuildfromsrc ./bin/linux-amd64/grafana-server

./bin/linux-amd64/grafana-server要求npm run build一次完成所有文件的构建。当前脚本将在构建完成之前执行它。

我想要的是在执行bash文件中的第二条命令之前,它应该等待容器内的命令首先完成。这可能吗?

一个重要的注意事项: grafana-server未完成时,"Failed to detect generated javascript files in public/buildnpm run watch

我该如何实现?

2 个答案:

答案 0 :(得分:0)

最简单的解决方案可能在npm run build之前运行npm run watch

答案 1 :(得分:0)

扩展@AussiDan的答案,我将Dockerfile更改为:

FROM golang:1.9 AS build-go
RUN go get github.com/grafana/grafana; exit 0
WORKDIR $GOPATH/src/github.com/grafana/grafana
RUN go run build.go setup && go run build.go build

FROM node:8 AS build-node
COPY --from=build-go $HOME/go/src/github.com/grafana/grafana .
RUN npm install -g yarn && yarn install --pure-lockfile && npm run build
CMD ./bin/linux-amd64/grafana-server

EXPOSE 3000

因此,当我启动grafana服务器时,内置的javascript文件已在图像中。