gin
gin copied to clipboard
Docker integration?
It's pretty straightforward to ship a Go app using e.g. google/golang, but I'm not sure how to setup an environment that works with gin. Any ideas?
Are you intending to use this in a production or a development environment.
gin wasn't originally intended to run in production, but you use case interests me :smile:
My idea was to have gin running in a container and have the code in a volume. Thus, when you git pull on the host machine you get the new code deployed automatically. The issue is that you lose control of dependencies, as you can't go get inside the container. Anyway, I think this might be an interesting model for CD, albeit slightly silly.
You can use gin with Vagrant and the official golang image like this:
Vagrantfile
config.vm.define "app" do |v|
v.vm.synced_folder ".", "/vagrant", disabled: true
v.vm.synced_folder ".", "/go/src/app"
v.vm.provider "docker" do |d|
d.build_dir = "."
d.ports = ["80:3000"]
end
end
Dockerfile
FROM golang:onbuild
RUN go get github.com/codegangsta/gin
CMD ["gin"]
EXPOSE 3000
While using the golang:1.4-wheezy and a simple martini example within a docker container, I get http: proxy error: dial tcp 127.0.0.1:3001: connection refused.
Here's the dockerfile and example code I'm using:
https://gist.github.com/caiges/3527b9213ce841f511fe
and the command I'm using:
gin --path /opt/helloworld /opt/helloworld/main.go
When I integrate Gin within Docker I receive this error message:
"/go/bin/gin: 1: /go/bin/gin: Syntax error: "(" unexpected"
Any ideas?
Hmm, haven't observed that behavior. Can you link your code?
It´s a concept test only:
[server.go]
package main
import "github.com/go-martini/martini"
func main() { m := martini.Classic() m.Get("/", func() string { return "Hello world!" }) m.Run() }
[Dockerfile]
FROM ubuntu:13.10
RUN apt-get update RUN apt-get install -y build-essential mercurial git subversion wget curl bzr
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install golang
RUN mkdir /go RUN export GOPATH=/go ENV GOPATH /go RUN export PATH=$PATH:$GOPATH/bin ENV PATH $PATH:$GOPATH/bin
WORKDIR /go
RUN go get github.com/tools/godep RUN go get github.com/go-martini/martini RUN go get github.com/codegangsta/gin
CMD go install lifes.com && gin --path src/lifes.com/ src/ lifes.com/server.go
2015-01-27 18:18 GMT+01:00 Caige Nichols [email protected]:
Hmm, haven't observed that behavior. Can you link your code?
— Reply to this email directly or view it on GitHub https://github.com/codegangsta/gin/issues/35#issuecomment-71687545.
Hmm, might be something in the lifes.com repo you're using. I slightly modified your Dockerfile, built with docker built -t testapp and was able to run docker run testapp gin --path /usr/src/app /usr/src/app/main.go
Yeah! Thanks caiges! now this part is working but now I received the following error message:
$ docker run -p 3000:3000 lifes-server gin --path src/lifes.com/ src/lifes.com/server.go [gin] listening on port 3000 2015/01/27 18:33:52 http: proxy error: dial tcp 127.0.0.1:3001: connection refused
Any ideas?
Thank you so much!
I just released my Docker Container which runs gin. https://github.com/ntboes/docker-golang-gin https://registry.hub.docker.com/u/ntboes/golang-gin/
Usage:
docker run --name some-instance-name -v $(pwd):/go/src/app ntboes/golang-gin -p 4000
@Raul-diffindo I had the same error when I was running without the CGO_ENABLED=0 flag