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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料