Building Docker within Docker for Go program -
i'm trying build small docker container go program. i'm hoping use docker container build go program (within container) build docker container run program.
here's build dockerfile:
from google/golang workdir /gopath/src/mycompany/mygoprog # build contributors application run mkdir -p /gopath/src/mycompany/mygoprog add ./src/* /gopath/src/mycompany/mygoprog/ run cgo_enabled=0 goos=linux go build -a -tags rs -ldflags '-w' /gopath/src/mycompany/mygoprog/*.go run cp mygoprog /mygoprog cmd docker build -t foobar /gopath/src/mycompany/mygoprog
my source directory has go program (trivial--compiles/runs) , dockerfile final product:
from scratch add /mygoprog mygoprog entrypoint ["/mygoprog"] expose 9100
these files organized thusly:
/myproject dockerfile /src dockerfile mygoprog.go
to launch build go top directory , run:
docker build .
this runs without errors....and no final image! output looks this:
bash-3.2$ docker build . sending build context docker daemon 6.656 kb sending build context docker daemon step 0 : google/golang ---> 3cc1d7ae0e9c step 1 : workdir /gopath/src/mycompany/mygoprog ---> using cache ---> 49b9686dcbed step 2 : run mkdir -p /gopath/src/mycompany/mygoprog ---> using cache ---> 0d0139bb8cae step 3 : add ./src/* /gopath/src/mycompany/mygoprog/ ---> 964ea5ca6afb removing intermediate container e57719a417d5 step 4 : run cgo_enabled=0 goos=linux go build -a -tags rs -ldflags '-w' /gopath/src/mycompany/mygoprog/*.go ---> running in 608ad65db52c ---> 6e91f06b7654 removing intermediate container 608ad65db52c step 5 : run cp mygoprog /mygoprog ---> running in 196af3db881b ---> 5e90e11ffc7d removing intermediate container 196af3db881b step 6 : cmd docker build -t foobar /gopath/src/mycompany/mygoprog ---> running in 4794354abf2b ---> d91a908ee663 removing intermediate container 4794354abf2b built d91a908ee663
what missing final, runnable docker compiled program inside?
you've produced docker image, haven't specified tag accessible hash (d91a908ee663). better specify tag: docker build -t mygoprog .
, if try run image without additional setting fail because there no docker inside of it. easiest solution here give access docker daemon container:
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker mygoprog
docker location different in distro, may need --privileged
flag.
Comments
Post a Comment