0

I'm building gogs from source and using

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

to add the folder containing the built gogs bin and it's files to my container.

If I cd to /home/git/go/src/github.com/gogits/gogs I can see the file, I can chmod +x it , ls -l it to see permissions and ownership etc etc. However I can't seem to run it. Every way I try I get:

/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

Running ls -l . within the gogs directory:

/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

Other stuff I've tried:

/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

Exec'ng into the docker container with the command sh I start to get weird errors after sometime, it may be tend to happen after I've added to PATH the gogs bin, can't remember for sure, but this has happened before

/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

Also when I did try to build gogs from source within the container I got a Segmentation Fault (core dump) sth like that. I tested it with valgrind and got sth like Bad permissions for mapped region at address 0x1340F80

Requested info:

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
Jonathan
  • 10,792
  • 5
  • 65
  • 85
  • List your full Dockerfile. Could you also list your environment inside the container using `env`. – Bernard Aug 28 '16 at 08:54
  • doing that right now – Jonathan Aug 28 '16 at 08:57
  • just added the files – Jonathan Aug 28 '16 at 09:00
  • Also how do you build gogs? Unless you're statically linking the go libs, they are not in the Alpine based container. Even then, Alpine doesn't have the `libc` library used for CGO networking. There are work around for those but the first thing I would do is to see that it works with `FROM golang:1.7`. Then, try using a lighter image `FROM debian` which does contain libc. – Bernard Aug 28 '16 at 09:29
  • I've read a couple of comments on static linking but I'm not sure how exactly to do that. I've tested this with debian:jessie mounting the same folders and files and gogs does work. I'm following the instructions on installing from the develop branch on the gogs site. Basically go get -u -tag "sqlite" then go build. I'm doing the build on ubuntu 16.04 – Jonathan Aug 28 '16 at 10:25

1 Answers1

1

The main problem is that you're using an image which doesn't have the Go libraries needed. I suspect that you're also not compiling your Go application for your target OS.

  1. Cross compile

    If you're compiling your app in Mac or Windows, you have to cross compile it. To target 64 bit linux (Debian/Ubuntu), it's like this.

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

    The flags for other OS's are here https://golang.org/doc/install/source#environment.

    It's a good idea to name your output binary with the name of the target platform (_linux-amd64).

  2. Use the official golang:1.7 image

    That's the simplest way to do it. The image will already include all the libraries needed.

Later on, you can look into optimising your image size. That's when static linking and Alpine becomes useful but they have their own sets of gotchas (no libc so DNS might not resolve correctly depending on your app). They can be worked around but it might not be worth your time now.

Bernard
  • 16,149
  • 12
  • 63
  • 66
  • I previously built this image with golang:1.6 and got an image size of 1 Gb+ golang by itslelf is around 700mb. I've actually just tried creating a statically linked bin with ` CGO_ENABLED=0 go get -a -ldflags '-s' -tags "sqlite" -u ./...` within the gogs folder however I get `package github.com/mattn/go-sqlite3: C source files not allowed when not using cgo or SWIG: sqlite3-binding.c` not sure how to proceed – Jonathan Aug 28 '16 at 12:30
  • Installing gogs with the following; `WORKDIR $GOPATH/src/github.com/gogits` `git clone --depth=1 -b develop https://github.com/gogits/gogs` `cd gogs; go get -tags "sqlite" -u ./...` `go build -tags "sqlite"` – Jonathan Aug 28 '16 at 12:45
  • A common way now is to build it inside a golang container but deploy it (COPY) inside a Debian container (~160MB). Build using `docker run --rm -v "$PWD":/go/src/github.com/myco/myapp \ -w /go/src/github.com/myco/myapp golang:1.7 \ go build -a -ldflags '-s' -o myapp_linux-amd64` Then you can COPY it in a `FROM: debian:8.5` image. – Bernard Aug 28 '16 at 13:14
  • As for your other error, it's because you're linking in C libraries, which have a dependency on the C networking lib (libc). libc is only used when `CGO_ENABLED=1` – Bernard Aug 28 '16 at 13:15
  • no need to run go get like above? and the resulting bin still won't work in alpine? I'm building on ubuntu 16.04 – Jonathan Aug 28 '16 at 13:24