I need to compile a Golang application for Linux and I can't cross-compile under Mac, because of another library. So I decided to compile within a Docker container. This is my first time to use Docker.
This is my current directory structure:
.
├── Dockerfile
├── Gopkg.lock
├── Gopkg.toml
├── Vagrantfile
├── bootstrap.sh
├── src
│ ├── cmd
│ │ ├── build.bat
│ │ ├── build.sh
│ │ ├── config.json
│ │ ├── readme.md
│ │ └── server.go
│ ├── consumers.go
│ ├── endpoints
│ │ ├── json.go
│ │ ├── rate.go
│ │ ├── test_payment.go
│ │ └── wallet.go
│ ├── middleware
│ │ └── acl.go
│ ├── models.go
│ ├── network
│ │ └── network.go
│ ├── qr
│ │ └── qr.go
│ ├── router
│ │ └── router.go
│ ├── service
│ │ └── walletService.go
│ ├── services.go
│ ├── setup.sql
│ ├── store
│ │ └── wallet.go
│ ├── stores.go
│ └── wallet
│ ├── coin.go
│ └── ethereum.go
Dockerfile:
FROM golang:latest
WORKDIR /src/cmd
RUN ls
RUN go get github.com/go-sql-driver/mysql
RUN go build -o main ./src/cmd/server.go
CMD ["./main"]
I try to build the Docker image with:
docker build -t outyet .
This is the error it returns:
Sending build context to Docker daemon 5.505MB
Step 1/6 : FROM golang:latest
---> d0e7a411e3da
Step 2/6 : WORKDIR /src/cmd
---> Using cache
---> 0c4c2b99e294
Step 3/6 : run ls
---> Using cache
---> 23d3e491a2e1
Step 4/6 : RUN go get github.com/go-sql-driver/mysql
---> Running in f34447e51f6c
Removing intermediate container f34447e51f6c
---> 5731ab22ee43
Step 5/6 : RUN go build -o main server.go
---> Running in ecc48fcf5488
stat server.go: no such file or directory
The command '/bin/sh -c go build -o main server.go' returned a non-zero code: 1
How i can build my Golang application with docker?