近来需要在服务器上起一个c++编译后的socket服务,
RUN 在docker里是用来生成镜像的
在使用
RUN ./server
后,因为服务一致开启所以卡住了,无法生成镜像;
CMD [./server]
生成了镜像,但是在一段时间后自动推出,不知道为什么;
ENTRYPOINT [./server]
可以正常使用了,在开始容器后可以正常对外提供服务;
在网上查了一下他们的区别:
Use RUN instructions to build your image by adding layers on top of initial image.
Prefer ENTRYPOINT to CMD when building executable Docker image and you need a command always to be executed. Additionally use CMD if you need to provide extra default arguments that could be overwritten from command line when docker container runs.
Choose CMD if you need to provide a default command and/or arguments that can be overwritten from command line when docker container runs.