Here's my Dockerfile:
FROM golang
RUN apt-get update
RUN go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
This generates this error:
package github.com/golang/protobuf/{proto,protoc-gen-go}: invalid github.com/ import path "github.com/golang/protobuf/{proto,protoc-gen-go}"
But, if I take out that RUN
directive, and just load up /bin/bash
in the docker container, I can run the go get
command just fine.
What's going on?
It's happening because the default shell is not /bin/bash
, it's sh
. You have two possible solutions, either you can explicitly define a shell in your RUN command like so:
RUN ["/bin/bash", "-c", "go get -u github.com/golang/protobuf/{proto,protoc-gen-go}"]
Or you can change the shell that RUN
uses by default like so:
SHELL ["/bin/bash", "-c"]
RUN go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
Source: https://docs.docker.com/engine/reference/builder/#/shell
It works if I use another shell, like bash, and put double quotes for the go
command
RUN bash -c "go get github.com/golang/protobuf/{proto,protoc-gen-go}"
By the way, you can do all in only one RUN, see Dockerfiles best practices
https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.