小编Not*_*ter的帖子

使用Dockerfile时找不到二进制文件

我正在遵循Go的Docker说明。他们的榜样对我有用。我现在试图修改它以运行tcp服务器:

go get github.com/Kelindar/tcp
Run Code Online (Sandbox Code Playgroud)

添加一个Dockerfile:

FROM golang

ADD . /go/src/github.com/Kelindar/tcp
RUN go install github.com/Kelindar/tcp

ENTRYPOINT /go/bin/tcp

EXPOSE 8080
Run Code Online (Sandbox Code Playgroud)

然后,我将其构建:

docker build --no-cache -t tcp .
Run Code Online (Sandbox Code Playgroud)

建立输出:

Sending build context to Docker daemon    322kB
Step 1/5 : FROM golang
 ---> 9fe4cdc1f173
Step 2/5 : ADD . /go/src/github.com/Kelindar/tcp
 ---> 10abce658324
Step 3/5 : RUN go install github.com/Kelindar/tcp
 ---> Running in 59dc47b30474
Removing intermediate container 59dc47b30474
 ---> 8fab53d2882c
Step 4/5 : ENTRYPOINT /go/bin/tcp
 ---> Running in 18d4b5befccb
Removing intermediate container 18d4b5befccb …
Run Code Online (Sandbox Code Playgroud)

go docker

1
推荐指数
1
解决办法
145
查看次数

无法运行程序:collect2:错误:ld 返回 1 退出状态

我已经查看了usr/bin/ld:cannot find -l<nameOfTheLibrary>中的答案,但它们都不适用于此上下文。

我刚刚买了一台新笔记本电脑并设置了 Go。一个简单的 hello world 程序可以工作,但是当我尝试一个更复杂的程序时,我得到:

go run .
# runtime/cgo
/usr/bin/ld: cannot find -lavcodec
/usr/bin/ld: cannot find -lavformat
/usr/bin/ld: cannot find -lavutil
/usr/bin/ld: cannot find -lswscale
/usr/bin/ld: cannot find -lswresample
/usr/bin/ld: cannot find -lavdevice
/usr/bin/ld: cannot find -lavfilter
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我不确定我的程序中哪里发生了错误,因为上面是我得到的唯一输出。

$ gcc --version
gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0
Run Code Online (Sandbox Code Playgroud)

编辑:这是一个重现错误的小样本:

package main

import "net/http"

func main() {
    cli := &http.Client{}
    rsp, err := cli.Get("https://google.com")
    if err != nil {
        panic(err)
    }

    defer …
Run Code Online (Sandbox Code Playgroud)

c linux go cgo

0
推荐指数
1
解决办法
3149
查看次数

标签 统计

go ×2

c ×1

cgo ×1

docker ×1

linux ×1