spf13 / cobra-cli

Cobra CLI tool to generate applications and commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot run in docker img: busybox,scratch; output: . /bin: no such file or directory

szerr opened this issue · comments

commented

my bin:

cobra-cli init --viper
Your Cobra application is ready at ...

sudo docker build -t bin . && sudo docker run -it --rm bin
Step 1/3 : FROM scratch
---> 
Step 2/3 : COPY ${PWD}/bin .
---> f18dcc8e0e25
Step 3/3 : ENTRYPOINT ["./bin"]
---> Running in dc5fd26d812f
Removing intermediate container dc5fd26d812f
---> ee78f634bd9f
Successfully built ee78f634bd9f
Successfully tagged bin:latest
exec ./bin: no such file or directory

my Dockerfile

FROM scratch
COPY ${PWD}/bin .
ENTRYPOINT ["./bin"]

About...

debian and local is fine
golang: 1.18.2
cobra: 1.4.0
viper: 1.11.0

Hello @szerr. The cobra-cli generator will generate go code which still needs to be built into a binary. Did you run go build on the generated code?

commented

Yes, I executed go build -o bin immediately after running cobra-cli init --viper.
And, strangely enough, it works fine in the debian image.

Moved this issue into spf13/cobra-cli since this looks to be mostly a cobra-cli question.

This is working fine for me, although, I did modify your Dockerfile and you may want to run some best practices and not build a scratch 1 layer image to run your built binary:

FROM busybox
COPY bin /usr/local/my-bin
ENTRYPOINT ["/usr/local/my-bin"]

I built the binary as you mentioned with

cobra-cli init --viper
go build -o bin

I'm also able the run that binary fine:

❯ ./bin
A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.

Closing since it appears cobra-cli is working fine and this is mostly related to using and building Docker. Feel free to continue to convo!!