0

我正在从源头构建 gogs 并使用

COPY gogs /home/git/go/src/github.com/gogits/gogs

将包含已构建 gogs bin 的文件夹及其文件添加到我的容器中。

如果我cd可以/home/git/go/src/github.com/gogits/gogs看到该文件,我可以 chmod +x it , ls -l it 查看权限和所有权等。但是我似乎无法运行它。我尝试的每一种方式都得到:

/home/git/go/src/github.com/gogits/gogs # cat /var/log/gogs/stderr.log
/bin/ash: /home/git/go/src/github.com/gogits/gogs/gogs: not found
/bin/ash: /home/git/go/src/github.com/gogits/gogs/gogs: not found
/bin/ash: /home/git/go/src/github.com/gogits/gogs/gogs: not found

ls -l .在 gos 目录中运行:

/home/git/go/src/github.com/gogits/gogs # ls -l .
total 33148
-rw-r--r--    1 git      nogroup        613 Aug 27 09:22 Dockerfile
-rw-r--r--    1 git      nogroup        913 Aug 27 09:22 Dockerfile.rpi
-rw-r--r--    1 git      nogroup       1054 Aug 27 09:22 LICENSE
-rw-r--r--    1 git      nogroup       1792 Aug 27 09:22 Makefile
-rw-r--r--    1 git      nogroup       7852 Aug 27 09:22 README.md
-rw-r--r--    1 git      nogroup       5331 Aug 27 09:22 README_ZH.md
drwxr-xr-x    2 git      nogroup       4096 Aug 28 08:33 cmd
drwxr-xr-x   10 git      nogroup       4096 Aug 28 08:33 conf
drwxr-xr-x    5 git      nogroup       4096 Aug 28 08:35 custom
drwxr-xr-x    2 git      nogroup       4096 Aug 28 08:33 data
drwxr-xr-x    4 git      nogroup       4096 Aug 28 08:33 docker
-rw-r--r--    1 git      nogroup       5359 Aug 27 09:22 glide.lock
-rw-r--r--    1 git      nogroup       1756 Aug 27 09:22 glide.yaml
-rwxr-xr-x    1 git      nogroup   33831440 Aug 27 10:12 gogs
-rw-r--r--    1 git      nogroup        839 Aug 27 09:22 gogs.go
drwxr-xr-x    2 git      nogroup       4096 Aug 28 08:33 log
drwxr-xr-x    4 git      nogroup       4096 Aug 28 08:33 models
drwxr-xr-x   34 git      nogroup       4096 Aug 28 08:33 modules
drwxr-xr-x    4 git      nogroup       4096 Aug 28 08:33 packager
drwxr-xr-x   14 git      nogroup       4096 Aug 28 08:33 public
drwxr-xr-x   14 git      nogroup       4096 Aug 28 08:33 routers
drwxr-xr-x   12 git      nogroup       4096 Aug 28 08:33 scripts
-rw-r--r--    1 root     root          2750 Aug 28 08:43 supervisord.log
-rw-r--r--    1 root     root             2 Aug 28 08:43 supervisord.pid
drwxr-xr-x   18 git      nogroup       4096 Aug 28 08:33 templates

我尝试过的其他东西:

/home/git/go/src/github.com/gogits/gogs # cp gogs /usr/bin
/home/git/go/src/github.com/gogits/gogs # /usr/bin/gogs
ash: /usr/bin/gogs: not found
/home/git/go/src/github.com/gogits/gogs # ls /usr/bin | grep gogs
gogs
/home/git/go/src/github.com/gogits/gogs # /usr/bin/gogs
ash: /usr/bin/gogs: not found
/home/git/go/src/github.com/gogits/gogs # ./usr/bin/gogs
ash: ./usr/bin/gogs: not found
/home/git/go/src/github.com/gogits/gogs # ls /usr/bin/gogs
/usr/bin/gogs

使用命令执行到 docker 容器中,sh一段时间后我开始出现奇怪的错误,这可能是在我将 gogs bin 添加到 PATH 之后发生的,不能确定,但​​这之前发生过

/home/git/go/src/github.com/gogits/gogs # gogs
sh: gogs: not found
/home/git/go/src/github.com/gogits/gogs # ./gogs
sh: ./gogs: not found
/home/git/go/src/github.com/gogits/gogs # export PATH=PATH:/home/git/go/src/github.com/gogits/gogs
/home/git/go/src/github.com/gogits/gogs # gogs
sh: gogs: not found
/home/git/go/src/github.com/gogits/gogs # cp gogs /usr/bin
sh: cp: not found
/home/git/go/src/github.com/gogits/gogs # cp gogs /usr/bin
sh: cp: not found
/home/git/go/src/github.com/gogits/gogs # cp
sh: cp: not found
/home/git/go/src/github.com/gogits/gogs # ls
sh: ls: not found

此外,当我尝试从容器内的源代码构建 gogs 时,我遇到了类似的分段错误(核心转储)。我用 valgrind 对其进行了测试并得到了类似的东西Bad permissions for mapped region at address 0x1340F80

要求的信息:

FROM alpine:edge

MAINTAINER jonathan@saharacluster.com

ENV DEBIAN_FRONTEND noninteractive

COPY gogs /home/git/go/src/github.com/gogits/gogs

WORKDIR /home/git/go/src/github.com/gogits/gogs

RUN apk update && apk add --update \
    openssh \
    curl\
    git\
    supervisor ;\
    rm -rf /var/lib/apt/lists/* ;\
    adduser -S -g 'Gogs' git;\
    mkdir -p custom/conf \
    log\
    data\
    /var/log/gogs\
    /home/git/.ssh\
    /home/git/data\
    /var/run/sshd\
    /var/log/install\
    /var/log/sshd;\
    touch /home/git/.ssh/authorized_keys\
    /home/git/setup.sh \
    /home/git/data/gogs.db;\
    chmod 700 /home/git/.ssh && chmod 600 /home/git/.ssh/authorized_keys;\
    chown -R git: /var/log/gogs /var/log/sshd /home/git

COPY app.ini custom/conf/app.ini

COPY supervisord.conf /home/git/supervisord.conf

COPY docker-entrypoint.sh /home/git/docker-entrypoint.sh

COPY setup.sh /home/git/setup.sh

RUN chmod +x /home/git/docker-entrypoint.sh /home/git/setup.sh

EXPOSE 22 3000

ENV DEBIAN_FRONTEND dialog

ENTRYPOINT ["/home/git/docker-entrypoint.sh"]

环境

GOGS_USER_PASSWORD=mypassword
HOSTNAME=e11c1f1b65cd
SHLVL=1
HOME=/root
DOMAIN=abc.com
GOGS_USER_EMAIL=gogsuser@abc.com
APP_NAME=sc
API_USER_PASSWORD=mypassword
TERM=xterm
GOGS_USER=gogsuser
API_USER_EMAIL=apiuser@abc.com
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DEBIAN_FRONTEND=dialog
PWD=/home/git/go/src/github.com/gogits/gogs
API_USER=apiuser
4

1 回答 1

1

主要问题是您使用的图像没有所需的 Go 库。我怀疑你也没有为你的目标操作系统编译你的 Go 应用程序。

  1. 交叉编译

    如果你在 Mac 或 Windows 中编译你的应用程序,你必须交叉编译它。以 64 位 linux (Debian/Ubuntu) 为目标,是这样的。

    GOOS=linux GOARCH=amd64 go build -o myapp_linux-amd64 .
    

    其他操作系统的标志在这里https://golang.org/doc/install/source#environment

    使用目标平台的名称 ( ) 来命名您的输出二进制文件是个好主意_linux-amd64

  2. 使用官方golang:1.7图片

    这是最简单的方法。该图像将已经包含所需的所有库。

稍后,您可以考虑优化图像大小。那是静态链接和 Alpine 变得有用的时候,但它们有自己的陷阱集(没有 libc,因此 DNS 可能无法正确解析,具体取决于您的应用程序)。它们可以解决,但现在可能不值得你花时间。

于 2016-08-28T11:40:28.550 回答