docker - 如何解决使用docker安装go的app出现 "undefined: math.Round"的问题

标签 docker go

我制作了 golang api 的代码,并在其中导入了一些包,例如 math。但是在通过运行 sudo docker build -t users/micro 构建图像时。 然后在一个步骤中它会给我错误。

错误

 Step 6/8 : RUN go install
 ---> Running in 454784b3ceef
 # bkapiv/users/utils
 utils/CommonFunctions.go:189:9: undefined: math.Round

docker 文件

# Start from a Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go.
FROM golang:1.9.6


WORKDIR /go/src/bkapiv/users

# Copy the local package files to the container's workspace.
ADD . /go/src/bkapiv/users

# Build the outyet command inside the container.
# (You may fetch or manage dependencies here,
# either manually or with a tool like "godep".)
RUN cd /go/src
RUN go-wrapper download   # "go get -d -v ./..."
RUN go install

# Run the outyet command by default when the container starts.
ENTRYPOINT /go/bin/users

# Document that the service listens on port 8080.
EXPOSE 8080

导入的包是

package utils

import (
 "bytes"
 "fmt"
 "math"
 "math/rand"
 "os/exec"
 "reflect"
 "sort"
 "strconv"
 "time"
)

 187 func Round(x, unit float64) float64 {
 188        // for this line it will giving me the error 
 189    return math.Round(x/unit) * unit
 190 }

我将如何解决我的错误

最佳答案

math 包中的函数 Round() 仅在 Go 1.10 (see the release notes) 中引入。您的 Dockerfile 使用较旧的 1.9.6 版本,因此您必须升级。

关于docker - 如何解决使用docker安装go的app出现 "undefined: math.Round"的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52588365/

相关文章:

docker - 在Windows中移至WSL 2后向Docker容器分配内存

linux - `sudo` 带命令替换

docker - 从 docker 容器创建 OpenVPN 连接

go - 独立于平台的 go build 用于工程师测试

go - 未命名指针返回值的预期标识符

docker - 拉取 Docker 镜像 - 未找到 list

mongodb - 如何删除不存在的docker镜像

docker - 将Go Server作为Docker容器运行时权限被拒绝错误

按频率图对字符串 slice 进行排序

validation - 在 GO 中使用标准包验证 URL