dongliuzi3410 2018-12-04 19:28
浏览 41
已采纳

带有Go CLI项目的Docker

I use the following docker file which works as expected The project is a cli and when I run command docker run -it cli I got error from the cli (which is ok since the entry point is just running fzr ENTRYPOINT ["./fzr”])

Typically I run in on my machine like fzr -help or fzr version etc

I want that when I use command like docker run -it cli that I will be able to run commands inside the container

like fzr -help and fzr version, how can I do that ?

FROM golang:1.10.5 AS build-env


ADD https://github.com/golang/dep/releases/download/v0.4.2/dep-linux-amd64 /usr/bin/dep
RUN chmod +x /usr/bin/dep

RUN mkdir -p $GOPATH/src/github.com/fzr
WORKDIR  $GOPATH/src/github.com/fzr


COPY Gopkg.toml Gopkg.lock ./

# install project dep
RUN dep ensure 

COPY . ./

RUN  go build  -o /fzr

FROM scratch
COPY --from=build-env /fzr ./
ENTRYPOINT ["./fzr"]
  • 写回答

1条回答 默认 最新

  • doutan1857 2018-12-04 19:34
    关注

    TL;DR; docker run -it cli version

    If you set ENTRYPOINT to your binary then everything that you pass after image name will be used as arg to that binary. If for some reason you need to overwrite entrypoint use --entrypoint flag to docker run.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致