安装到高山容器的bin无法运行/找不到gogs

时间:2016-08-28 08:45:23

标签: docker ash alpine gogs

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

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它可以查看权限和所有权等等。但是我似乎无法运行它。我尝试的每一种方式都得到:

/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

在gogs目录中运行ls -l .

/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

使用命令sh执行到docker容器中我在一段时间后开始出现奇怪的错误,它可能倾向于在我添加到PATH之后发生了gogs bin,无法确定,但这发生在

之前
/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

当我尝试从容器中的源代码构建gog时,我得到了一个Segmentation Fault(核心转储)......就像那样。我用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"]

的env

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

1 个答案:

答案 0 :(得分: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图片

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

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