3

I have created dockerfile, successfully built it, but when I run it

sudo docker run -d -it -p 15555:9888 --name=docker-golang-test goTestDocker go run main.go host=0.0.0.0

it returns an error

docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"go\": executable file not found in $PATH": unknown.

This is my Docker file

FROM golang:1.10.2-alpine3.7 AS build 
RUN apk --no-cache add gcc g++ make ca-certificates
WORKDIR /home/user/Desktop/work/go-work/GoProject/project
RUN ls
RUN pwd
COPY . .
RUN pwd
RUN apk update -qq && apk add git
RUN go get github.com/golang/protobuf/jsonpb
RUN go get github.com/golang/protobuf/proto
FROM alpine:3.7
WORKDIR /usr/bin
COPY --from=build /go/bin .
EXPOSE 9888
CMD ["./app"] --v
3
  • 1
    you should consider to check output of docker exec docker-golang-test which go / docker logs docker-golang-test Commented Nov 3, 2018 at 7:09
  • The Go image is only used as an intermediate build step. The final image is built FROM alpine:3.7, which doesn't contain Go. Commented Nov 3, 2018 at 7:42
  • what does sudo docker run -d -it --name=docker-golang-test goTestDocker which go return? Commented Nov 3, 2018 at 10:59

1 Answer 1

2
FROM golang:1.10.2-alpine3.7 AS build 
RUN apk --no-cache add gcc g++ make ca-certificates
WORKDIR /go/src/github.com/{$whoami}/testProject
RUN ls
RUN pwd
COPY . .
RUN pwd
RUN apk update -qq && apk add git
RUN go get github.com/golang/protobuf/jsonpb
RUN go get github.com/golang/protobuf/proto
RUN go build .

FROM alpine:3.7
WORKDIR /usr/bin
COPY --from=build /go/src/github.com/{$whoami}/testProject/testProject .
EXPOSE 9888
CMD ["./app"] --v

this is a multistage dockerfile which you copy the project, fetch dependencies and build it, and then in second one, you just run it (by CMD ["./app"])

if you want to do it in your way:

FROM golang:1.10.2-alpine3.7
RUN apk --no-cache add gcc g++ make ca-certificates
WORKDIR /go/src/github.com/{$whoami}/testProject
COPY . .
RUN apk update -qq && apk add git
RUN go get github.com/golang/protobuf/jsonpb
RUN go get github.com/golang/protobuf/proto

is the dockerfile you want (my suggestion is ofc first one cause it runs just by docker run command)

PS: multistage dockerfile

Sign up to request clarification or add additional context in comments.

6 Comments

@GGG Are you sure that you really have Go tool chain in your image? EDIT: Be noticed that you have Go toolchain only in “build” stage. In main side, you're copying the executable from build and running it. So it's perfectly normal that you don't have go tools there. And as I can see, you already instructed CMD, so why are you trying to override it?
@Berkant, to tell the truth, I am a newbie in docker, and this dockerfile I have found in the internet, so I modified to be suitable in my project
@GGG You had better follow this reference: docs.docker.com/engine/reference/builder It will walk you through Dockerfile instructions in detail and there are examples too.
eddited my post
Thx, I choose the first one, It ran without ant error, but when I go to localhost:9888, there is nothing
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.