简体   繁体   English

使用 docker run 命令的 Docker 入口点

[英]Docker ENTRYPOINT using docker run command

I am running below command to set entrypoint through command line to start nginx service with this container我正在运行以下命令以通过命令行设置入口点以使用此容器启动 nginx 服务

root@server:~# docker run -it --entrypoint="/bin/bash /root/service.sh" docker-reg.sogeti-aws.nl:5000/ubuntu:v3 bash root@server:~# docker run -it --entrypoint="/bin/bash /root/service.sh" docker-reg.sogeti-aws.nl:5000/ubuntu:v3 bash

root@server:~# cat /root/service.sh root@server:~# cat /root/service.sh

!/bin/bash !/bin/bash

service nginx start while true; service nginx start while true; do sleep 1d;做睡眠1d; done完毕

so is it possible with docker run command or i need to define Dockerfile only那么是否可以使用 docker run 命令或者我只需要定义 Dockerfile

You can add the ENTRYPOINT instruction at the end of your Dockerfile.您可以在 Dockerfile 的末尾添加 ENTRYPOINT 指令。

ENTRYPOINT ["/bin/bash","/root/service.sh"]

Of course, you'll need to add the service.sh to your image.当然,您需要将 service.sh 添加到您的图像中。 Again using a Dockerfile再次使用 Dockerfile

COPY service.sh /root/service.sh

In the end it will be something like this.最终它会是这样的。

FROM docker-reg.sogeti-aws.nl:5000/ubuntu:v3

COPY service.sh /root/service.sh
ENTRYPOINT ["/bin/bash","/root/service.sh"]

To change the entry point to bash use the following command:要将入口点更改为 bash,请使用以下命令:

sudo docker run --entrypoint "/usr/bin/bash" -it <any-other-options> <img>

Note: don't add bash at the end, as we use to do when using -it .注意:不要在最后添加 bash,就像我们在使用-it时所做的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM