Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker support #27

Open
davidhunterxyz opened this issue Nov 12, 2015 · 7 comments
Open

Docker support #27

davidhunterxyz opened this issue Nov 12, 2015 · 7 comments
Labels
Milestone

Comments

@davidhunterxyz
Copy link
Member

Goal gives a error while trying to build a docker image with this dockerfile. It works if the project files are on a public github repo.

fatal: could not read Username for 'https://github.com': No such device or address
package github.com/davidhunter/goal-sample/server: exit status 128

FROM golang:onbuild
EXPOSE 8080

Then their is another issue where I can't connect to it outside a container.

@ghost ghost added the support label Nov 12, 2015
@ghost
Copy link

ghost commented Nov 12, 2015

@Davidhunter Not really something Goal specific as a project developed with Goal is just a regular Go app that can be built as follows:

go build github.com/davidhunter/goal-sample

So, any Dockerfile that works for a standard library based Go app will work for your project, too. E.g., Revel's Dockerfile from the thread:

FROM debian
RUN apt-get update

WORKDIR /home
ADD ./ /home

ENTRYPOINT /home/bin/run
EXPOSE 8080

In this case you have to have an already compiled binary of your project.

Alternatively, use this sample from Go language's docs, do not try to install Goal, install your project:

# Build the outyet command inside the container.
# (You may fetch or manage dependencies here,
# either manually or with a tool like "godep".)
RUN go install github.com/davidhunter/goal-sample

fatal: could not read Username for 'https://github.com': No such device or address
package github.com/davidhunter/goal-sample/server: exit status 128

Do you have access for git clone github.com/davidhunter/goal-sample/server? Here is a related SO question: Docker: go get from a private GitHub repo.

@ghost ghost self-assigned this Nov 12, 2015
@ghost
Copy link

ghost commented Nov 23, 2015

The issue has been resolved, it is not enough to listen on localhost:8080 (#32).

The way to run an app with the Dockerfile mentioned in the message above:

# Build the image and tag it as myImage (use whatever tag name you want).
docker build -t myImage .

# Run the app, publish container's :8080 port on the external :8080 port
# (format: `external_addr_or_port:container's_port`), give the app a predictable name.
docker run --publish 8080:8080 --name myApp

@ghost ghost closed this as completed Nov 23, 2015
@ghost ghost added this to the v0.0.2 milestone Nov 23, 2015
@davidhunterxyz
Copy link
Member Author

@alkchr I think a docker file inside the project skeleton would be useful for this project

@ghost
Copy link

ghost commented Dec 12, 2015

👍 Should it be a Dockerfile that uses golang:onbuild to compile the app and then start it as in your #27 (comment)? Or we can just copy already compiled binary from bin directory and use it with debian image as in my #27 (comment)?

@davidhunterxyz
Copy link
Member Author

golang:onbuild only worked for me if the Goal project repository was on github.com and I had to build the binary with env GOOS=linux go build -o bin/run for it to work in docker when just copying over the binary.

I am not sure if I am using golang:onbuild wrong or if their is a way to build the binary for mac and linux.

This Dockerfile seems to work when the install path is set to the same project gopath.

FROM golang:1.5

COPY . /go/src/github.com/colegion/goal/internal/skeleton
WORKDIR /go/src/github.com/colegion/goal/internal/skeleton

RUN go get -u github.com/colegion/goal/...
RUN go install github.com/colegion/goal/internal/skeleton

ENTRYPOINT /go/bin/skeleton

EXPOSE 8080

@ghost
Copy link

ghost commented Jan 23, 2016

This Dockerfile seems to work when the install path is set to the same project gopath.

Yeah, right. Because generated apps use absolute import paths (e.g. github.com/johndoe/forum/controllers instead of ./controllers). So, you have to keep the structure in order to compile the code.

Your Dockerfile looks good. Does it work without the RUN go get -u github.com/colegion/goal/...? If so, I would go with the following config:

FROM golang:1.5

COPY . /go/src/github.com/colegion/goal/internal/skeleton
WORKDIR /go/src/github.com/colegion/goal/internal/skeleton

# Flag "-d" means download only, do not install.
RUN go get -d github.com/colegion/goal/internal/skeleton
RUN go build -o ./bin/run github.com/colegion/goal/internal/skeleton

ENTRYPOINT ./bin/run --http.addr :8080

EXPOSE 8080

If this works, we can add to the skeleton and close this issue.

@davidhunterxyz
Copy link
Member Author

@alkchr Your docker file works

@ghost ghost removed their assignment Feb 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant