进入Golang Alpine Docker容器的正确shell程序是什么?

huangapple go评论78阅读模式
英文:

Correct shell program for entrypoint into golang alpine docker container?

问题

我正在尝试启动一个golang alpine的Docker容器(只使用基本镜像),并立即连接到它以运行命令,但是我似乎无法指定正确的shell程序。

docker run -d golang:1.20-alpine --entrypoint=bin/sh
ec90a5d5eeba63e509acc09e234054d883aa122cd7617f89b61e7d71220847cd
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "--entrypoint=bin/sh": stat --entrypoint=bin/sh: no such file or directory: unknown.

我还尝试过:/bin/sh。我在这里漏掉了什么?

英文:

I'm trying to spin up a golang alpine docker container (just the basic image) and immediately connect to it to run commands, but I can't seem to specify the correct shell program.

docker run -d golang:1.20-alpine --entrypoint=bin/sh
ec90a5d5eeba63e509acc09e234054d883aa122cd7617f89b61e7d71220847cd
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "--entrypoint=bin/sh": stat --entrypoint=bin/sh: no such file or directory: unknown.

I've also tried: /bin/sh. What am I missing here?

答案1

得分: 1

我会将代码部分翻译为中文,其他部分直接返回翻译好的内容:

要启动一个 golang alpine docker 容器(只使用基本镜像)并立即连接到它以运行命令,你可以这样做:

docker run -it golang:1.20-alpine /bin/sh

如果你想给容器命名,可以这样做:

docker pull golang:1.20-alpine
docker run -id --name=test5 golang:1.20-alpine
docker exec -it test5 /bin/sh

你可以使用 docker stop test5 -t 2 命令停止容器,并使用 docker start test5 命令重新启动它。

你可以使用 docker rm test5 命令删除容器。


你可以稍微修改你的命令以避免错误:

docker run -d --entrypoint=/bin/sh golang:1.20-alpine

注意 --entrypoint 命令行选项在 golang:1.20-alpine 之前。

英文:

I'll just write an answer instead of commands in comments.

To spin up a golang alpine docker container (just the basic image) and immediately connect to it to run commands, you can do this:

docker run -it golang:1.20-alpine /bin/sh

If you want to name your container, you could do this:

docker pull golang:1.20-alpine
docker run -id --name=test5 golang:1.20-alpine
docker exec -it test5 /bin/sh

You can stop the container with docker stop test5 -t 2 and start it up again using docker start test5.

You can remove it by doing docker rm test5.


You can change your command just a little bit to avoid the error:

docker run -d --entrypoint=/bin/sh golang:1.20-alpine

Notice that the --entrypoint command line switch is before golang:1.20-alpine.

huangapple
  • 本文由 发表于 2023年5月20日 03:03:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76291830.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定