嗨,
我试图在Jenkins管道中构建和运行Docker-Container,然后对容器中已部署的Web应用程序进行一些测试。问题是我的容器只存活了几秒钟,然后死于退出代码0。已经尝试在具有和不具有Docker Groovy插件的情况下以交互模式运行它。
我的管道代码如下:
stage("Docker Build&Run") {
steps {
script {
def tag = "shop:${env.BUILD_ID}"
docker.build(tag)
//sh "docker run -d -p 8443:443/tcp ${tag}" Tried both
docker.image(tag).run('-p 8443:443/tcp')
}
}
}
stage("Dummy Dynamic Analysis") {
steps {
echo "Dummy Dynamic Analysis" //to be integrated
sleep 120 //application should be available here since it has to be theire for testing as well
}
}
事件看起来像这样。几秒钟后被摧毁:
2018-11-07T17:27:30.104407703+01:00 image tag sha256:21ae4ef9603d390d0244cee30651485f2fb517a47c9e9d2c38855d093349105c (name=shop:35)
2018-11-07T17:27:31.260144894+01:00 container create ade7069d9d391146611f4f658156554823cc8086bd6769bbc32c3949d5b1a694 (image=shop:35, name=suspicious_liskov)
2018-11-07T17:27:31.456730373+01:00 network connect 36c2d6617773a7c7075caece71bcd744c89009b3db1962328d0f9930d981238a (container=ade7069d9d391146611f4f658156554823cc8086bd6769bbc32c3949d5b1a694, name=bridge, type=bridge)
2018-11-07T17:27:31.966564913+01:00 container start ade7069d9d391146611f4f658156554823cc8086bd6769bbc32c3949d5b1a694 (image=shop:35, name=suspicious_liskov)
2018-11-07T17:27:35.761690515+01:00 container die ade7069d9d391146611f4f658156554823cc8086bd6769bbc32c3949d5b1a694 (exitCode=0, image=shop:35, name=suspicious_liskov)
2018-11-07T17:27:35.929597196+01:00 network disconnect 36c2d6617773a7c7075caece71bcd744c89009b3db1962328d0f9930d981238a (container=ade7069d9d391146611f4f658156554823cc8086bd6769bbc32c3949d5b1a694, name=bridge, type=bridge)
如何部署容器并使它无限期运行直到停止运行,或者在jenkins整个运行期间至少保持运行?
预先感谢大家。 问候
答案 0 :(得分:0)
因此我的docker文件看起来像这样:
FROM ubuntu:14.04
RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d
ADD ./provision.sh /tmp/provision.sh
RUN /bin/bash /tmp/provision.sh
ENTRYPOINT service apache2 start && service mysql start && /bin/bash
EXPOSE 443
我刚刚意识到读了这篇文章:How to keep Docker container running after starting services?,当我的入口点调用完成时,docker容器将退出,并且只要我的服务还活着,它就不会活着。我认为这将会发生。我现在切换到建议的解决方案,该解决方案在有监督的条件下运行,并且运行良好。谢谢大家。
新的Dockerfile:
FROM ubuntu:14.04
RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d
RUN apt-get update && apt-get install supervisor -y
ADD ./provision.sh /tmp/provision.sh
ADD ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN /bin/bash /tmp/provision.sh
ENTRYPOINT ["/usr/bin/supervisord", "-n"]
EXPOSE 443
Conf主管:
[supervisord]
nodaemon=true
[program:mysql]
command=/usr/bin/pidproxy /var/run/mysqld/mysqld.pid /usr/sbin/mysqld
autorestart=true
[program:apache]
command=/usr/sbin/apache2ctl -DFOREGROUND
autorestart=true