sh: /bin/artisan: not found
如果Docker引擎主机是在Mac OS X中的VirtualBox VM中部署的busyBox(它是高山的基础),那么这个相同的二进制文件(为相同的操作系统和arch编译)将运行得很好.
如果容器基于Ubuntu映像之一,这个二进制文件也会运行得很好.
任何想法这个二进制文件丢失?
这是我做的重现(成功运行在VirtualBox / busyBox在OS X未显示):
构建(使用标志构建,即使拱形匹配):
➜ artisan git:(master) ✗ GOOS=linux GOARCH=amd64 go build
检查它可以在主机上运行:
➜ artisan git:(master) ✗ ./artisan 10:14:04.925 [ERROR] artisan: need a command,one of server,provision or build
复制到docker目录,构建,运行:
➜ artisan git:(master) ✗ cp artisan docker/build/bin/ ➜ artisan git:(master) ✗ cd docker ➜ docker git:(master) ✗ cat Dockerfile FROM docker:1.10 COPY build/ / ➜ docker git:(master) ✗ docker build -t artisan . Sending build context to Docker daemon 10.15 MB Step 1 : FROM docker:1.10 ... ➜ docker git:(master) ✗ docker run -it artisan sh / # /bin/artisan sh: /bin/artisan: not found
现在将图像基础改为phusion / baseimage:
➜ docker git:(master) ✗ cat Dockerfile #FROM docker:1.10 FROM phusion/baseimage COPY build/ / ➜ docker git:(master) ✗ docker build -t artisan . Sending build context to Docker daemon 10.15 MB Step 1 : FROM phusion/baseimage ... ➜ docker git:(master) ✗ docker run -it artisan sh # /bin/artisan 08:16:39.424 [ERROR] artisan: need a command,provision or build
我遇到了两个解决方案:
>禁用CGO,通过CGO_ENABLED = 0
>强制使用Go执行网络依赖关系,netgo通过go build -tags netgo -a -v,这是为某些平台实现的
从https://golang.org/doc/go1.2:
The net package requires cgo by default because the host operating system must in general mediate network call setup. On some systems,though,it is possible to use the network without cgo,and useful to do so,for instance to avoid dynamic linking. The new build tag netgo (off by default) allows the construction of a net package in pure Go on those systems where it is possible.
以上假定,唯一的CGO依赖是标准库的网络包.