Go build fails when building docker image
I'm a little new to golang and I'm still trying to get my head around the difference between go run main.go
and go build [-o] main.go
.
I've build a little gin app to try out locally with docker and kubernetes.
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main()
r := gin.Default()
r.GET("/healthz", func(c *gin.Context)
c.String(http.StatusOK, "")
)
r.GET("/readinez", func(c *gin.Context)
c.String(http.StatusOK, "")
)
r.Run() // listen and serve on 0.0.0.0:8080
The app runs perfectly fine with go run main.go
.
My Dockerfile:
FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]
It fails:
It is definitely in there and it also works when I go run main.go
. What is the difference to build?
I'm not sure what to do here. Coming from a node background. This does drive a noobie somewhat mad... Sure there is an easy solution.
docker go
add a comment |
I'm a little new to golang and I'm still trying to get my head around the difference between go run main.go
and go build [-o] main.go
.
I've build a little gin app to try out locally with docker and kubernetes.
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main()
r := gin.Default()
r.GET("/healthz", func(c *gin.Context)
c.String(http.StatusOK, "")
)
r.GET("/readinez", func(c *gin.Context)
c.String(http.StatusOK, "")
)
r.Run() // listen and serve on 0.0.0.0:8080
The app runs perfectly fine with go run main.go
.
My Dockerfile:
FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]
It fails:
It is definitely in there and it also works when I go run main.go
. What is the difference to build?
I'm not sure what to do here. Coming from a node background. This does drive a noobie somewhat mad... Sure there is an easy solution.
docker go
add a comment |
I'm a little new to golang and I'm still trying to get my head around the difference between go run main.go
and go build [-o] main.go
.
I've build a little gin app to try out locally with docker and kubernetes.
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main()
r := gin.Default()
r.GET("/healthz", func(c *gin.Context)
c.String(http.StatusOK, "")
)
r.GET("/readinez", func(c *gin.Context)
c.String(http.StatusOK, "")
)
r.Run() // listen and serve on 0.0.0.0:8080
The app runs perfectly fine with go run main.go
.
My Dockerfile:
FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]
It fails:
It is definitely in there and it also works when I go run main.go
. What is the difference to build?
I'm not sure what to do here. Coming from a node background. This does drive a noobie somewhat mad... Sure there is an easy solution.
docker go
I'm a little new to golang and I'm still trying to get my head around the difference between go run main.go
and go build [-o] main.go
.
I've build a little gin app to try out locally with docker and kubernetes.
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main()
r := gin.Default()
r.GET("/healthz", func(c *gin.Context)
c.String(http.StatusOK, "")
)
r.GET("/readinez", func(c *gin.Context)
c.String(http.StatusOK, "")
)
r.Run() // listen and serve on 0.0.0.0:8080
The app runs perfectly fine with go run main.go
.
My Dockerfile:
FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]
It fails:
It is definitely in there and it also works when I go run main.go
. What is the difference to build?
I'm not sure what to do here. Coming from a node background. This does drive a noobie somewhat mad... Sure there is an easy solution.
docker go
docker go
edited Nov 14 '18 at 11:57
mbuechmann
2,88721426
2,88721426
asked Nov 25 '17 at 14:01
TinoTino
1,28331948
1,28331948
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The program succeeds on your machine because you probably have the gin package installed. You can't assume a container will have it, and should install it explicitly. Just add the following line to your dockerfile before the go build
line:
RUN go get github.com/gin-gonic/gin
Thx that worked. How can one set this up more efficiently in the go world? Its not really practical to add every package manually to docker. Any good ideas articles/tutorials I could read?
– Tino
Nov 25 '17 at 14:29
2
One way is to vendor the gin-gonic package. Basicly means to copy the package over to your folder as a dependency. Please do look at dep and glide which should be the succesors of govendoring.
– Hace
Nov 25 '17 at 15:42
1
Incidentally, you can just run a nakedgo get
to pull all dependencies. That said, you (OP) may want to look into vendoring (blog.gopheracademy.com/advent-2015/vendor-folder). It solves both this issue and problems that arise from differing dependency versions. (Edit: damn, beat me to it, Hace)
– Kaedys
Nov 25 '17 at 15:42
add a comment |
It may have failed because you used gin, and the library cannot be found inside the container. Try to use glide or godep to vendoring third party library.
add a comment |
go get github.com/gin-gonic/gin
Then it should work.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47486811%2fgo-build-fails-when-building-docker-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The program succeeds on your machine because you probably have the gin package installed. You can't assume a container will have it, and should install it explicitly. Just add the following line to your dockerfile before the go build
line:
RUN go get github.com/gin-gonic/gin
Thx that worked. How can one set this up more efficiently in the go world? Its not really practical to add every package manually to docker. Any good ideas articles/tutorials I could read?
– Tino
Nov 25 '17 at 14:29
2
One way is to vendor the gin-gonic package. Basicly means to copy the package over to your folder as a dependency. Please do look at dep and glide which should be the succesors of govendoring.
– Hace
Nov 25 '17 at 15:42
1
Incidentally, you can just run a nakedgo get
to pull all dependencies. That said, you (OP) may want to look into vendoring (blog.gopheracademy.com/advent-2015/vendor-folder). It solves both this issue and problems that arise from differing dependency versions. (Edit: damn, beat me to it, Hace)
– Kaedys
Nov 25 '17 at 15:42
add a comment |
The program succeeds on your machine because you probably have the gin package installed. You can't assume a container will have it, and should install it explicitly. Just add the following line to your dockerfile before the go build
line:
RUN go get github.com/gin-gonic/gin
Thx that worked. How can one set this up more efficiently in the go world? Its not really practical to add every package manually to docker. Any good ideas articles/tutorials I could read?
– Tino
Nov 25 '17 at 14:29
2
One way is to vendor the gin-gonic package. Basicly means to copy the package over to your folder as a dependency. Please do look at dep and glide which should be the succesors of govendoring.
– Hace
Nov 25 '17 at 15:42
1
Incidentally, you can just run a nakedgo get
to pull all dependencies. That said, you (OP) may want to look into vendoring (blog.gopheracademy.com/advent-2015/vendor-folder). It solves both this issue and problems that arise from differing dependency versions. (Edit: damn, beat me to it, Hace)
– Kaedys
Nov 25 '17 at 15:42
add a comment |
The program succeeds on your machine because you probably have the gin package installed. You can't assume a container will have it, and should install it explicitly. Just add the following line to your dockerfile before the go build
line:
RUN go get github.com/gin-gonic/gin
The program succeeds on your machine because you probably have the gin package installed. You can't assume a container will have it, and should install it explicitly. Just add the following line to your dockerfile before the go build
line:
RUN go get github.com/gin-gonic/gin
edited Nov 25 '17 at 14:29
answered Nov 25 '17 at 14:26
MureinikMureinik
183k22135200
183k22135200
Thx that worked. How can one set this up more efficiently in the go world? Its not really practical to add every package manually to docker. Any good ideas articles/tutorials I could read?
– Tino
Nov 25 '17 at 14:29
2
One way is to vendor the gin-gonic package. Basicly means to copy the package over to your folder as a dependency. Please do look at dep and glide which should be the succesors of govendoring.
– Hace
Nov 25 '17 at 15:42
1
Incidentally, you can just run a nakedgo get
to pull all dependencies. That said, you (OP) may want to look into vendoring (blog.gopheracademy.com/advent-2015/vendor-folder). It solves both this issue and problems that arise from differing dependency versions. (Edit: damn, beat me to it, Hace)
– Kaedys
Nov 25 '17 at 15:42
add a comment |
Thx that worked. How can one set this up more efficiently in the go world? Its not really practical to add every package manually to docker. Any good ideas articles/tutorials I could read?
– Tino
Nov 25 '17 at 14:29
2
One way is to vendor the gin-gonic package. Basicly means to copy the package over to your folder as a dependency. Please do look at dep and glide which should be the succesors of govendoring.
– Hace
Nov 25 '17 at 15:42
1
Incidentally, you can just run a nakedgo get
to pull all dependencies. That said, you (OP) may want to look into vendoring (blog.gopheracademy.com/advent-2015/vendor-folder). It solves both this issue and problems that arise from differing dependency versions. (Edit: damn, beat me to it, Hace)
– Kaedys
Nov 25 '17 at 15:42
Thx that worked. How can one set this up more efficiently in the go world? Its not really practical to add every package manually to docker. Any good ideas articles/tutorials I could read?
– Tino
Nov 25 '17 at 14:29
Thx that worked. How can one set this up more efficiently in the go world? Its not really practical to add every package manually to docker. Any good ideas articles/tutorials I could read?
– Tino
Nov 25 '17 at 14:29
2
2
One way is to vendor the gin-gonic package. Basicly means to copy the package over to your folder as a dependency. Please do look at dep and glide which should be the succesors of govendoring.
– Hace
Nov 25 '17 at 15:42
One way is to vendor the gin-gonic package. Basicly means to copy the package over to your folder as a dependency. Please do look at dep and glide which should be the succesors of govendoring.
– Hace
Nov 25 '17 at 15:42
1
1
Incidentally, you can just run a naked
go get
to pull all dependencies. That said, you (OP) may want to look into vendoring (blog.gopheracademy.com/advent-2015/vendor-folder). It solves both this issue and problems that arise from differing dependency versions. (Edit: damn, beat me to it, Hace)– Kaedys
Nov 25 '17 at 15:42
Incidentally, you can just run a naked
go get
to pull all dependencies. That said, you (OP) may want to look into vendoring (blog.gopheracademy.com/advent-2015/vendor-folder). It solves both this issue and problems that arise from differing dependency versions. (Edit: damn, beat me to it, Hace)– Kaedys
Nov 25 '17 at 15:42
add a comment |
It may have failed because you used gin, and the library cannot be found inside the container. Try to use glide or godep to vendoring third party library.
add a comment |
It may have failed because you used gin, and the library cannot be found inside the container. Try to use glide or godep to vendoring third party library.
add a comment |
It may have failed because you used gin, and the library cannot be found inside the container. Try to use glide or godep to vendoring third party library.
It may have failed because you used gin, and the library cannot be found inside the container. Try to use glide or godep to vendoring third party library.
answered Nov 25 '17 at 14:20
ngurajekangurajeka
463
463
add a comment |
add a comment |
go get github.com/gin-gonic/gin
Then it should work.
add a comment |
go get github.com/gin-gonic/gin
Then it should work.
add a comment |
go get github.com/gin-gonic/gin
Then it should work.
go get github.com/gin-gonic/gin
Then it should work.
answered Nov 25 '17 at 14:26
Huang MingheHuang Minghe
237411
237411
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47486811%2fgo-build-fails-when-building-docker-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown