douxu0550 2015-02-03 15:25
浏览 42
已采纳

构建小容器以运行已编译的go代码

From https://docs.docker.com/articles/baseimages/

I am trying to build a base image to run compiled go code, from: https://github.com/tianon/dockerfiles/tree/master/true

  1. I have tried to copy into docker the true.go
    Then: exec: "/true": permission denied
  2. Also tried to bash into it, then: "bash"
    Then: executable file not found in $PATH
  3. Also tried to use the debootstrap raring raring > /dev/null
    Then: "bash": executable file not found in $PATH

How do you do this?

Thanks

  • 写回答

1条回答 默认 最新

  • duanpuchen3142 2015-02-03 18:09
    关注

    I'm not sure I entirely follow.

    The Dockerfile from the linked project builds an image with nothing in it except an executable - there will be no shell or compiler, so running bash will be impossible. It does this by using the special scratch base image, which is simply a completely empty filesystem.

    If you clone the repository and build the image using the Dockerfile (docker build -t go-image .), it will simply copy the executable directly into the image (note the Dockerfile copies the executable true-asm, not the source code true.go). If you then use docker run to start the image, it will run it (docker run go-image).

    Does that make sense? The code is compiled locally (or by another container) and the compiled, stand-alone executable is placed by itself into the image.

    Generally, you don't want to do this and definitely not when you're beginning - it will be easier for you to use a golang or debian image which will include basic tools such as a shell.

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

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题