Build Docker with Go app: cannot find package

前端 未结 6 747
独厮守ぢ
独厮守ぢ 2020-12-29 08:56

I have my Dockerfile in the root of directory with src/myapp folder, myapp contains myapp.go with main package.

Dockerfi

6条回答
  •  无人及你
    2020-12-29 09:10

    If the objective is to create a container that simply runs your binary, I would take different approach.

    First build the binary for linux:

    GOOS=linux CGO_ENABLED=0 go build -a -installsuffix cgo
    

    Then build a lightweight docker image from scratch:

    FROM scratch
    COPY myApp 
    CMD ["/myApp"]
    

提交回复
热议问题