简体   繁体   English

在Docker中构建Jenkins映像

[英]Build jenkins image in docker

Whenever I run: 每当我跑步时:

docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins

I lose all the changes I made to the jenkins image in a previous session and it always creates a new image. 我会丢失在上一个会话中对jenkins图像所做的所有更改,并且它始终会创建一个新图像。 Can some one please let me know why is this happening? 可以让我知道为什么会这样吗?

If you want to create your custom Docker image you can write your own Dockerfile: 如果要创建自定义Docker映像,可以编写自己的Dockerfile:

FROM jenkins/jenkins
COPY ...
RUN ...

The above is useful when you want to install different tools on your container or update configs which are not really Jenkins related. 当您想在容器上安装其他工具或更新与Jenkins无关的配置时,以上内容很有用。

All the jenkins related stuff is inside the directory /var/jenkins_home inside your container (job configurations, workspace, ...) 所有与jenkins相关的东西都位于容器内的目录/var/jenkins_home中(作业配置,工作空间等)。

If you want to persist this data you can try the following: 如果要保留此数据,可以尝试以下操作:

Create a named Docker volume and mount the data from your container inside the volume. 创建一个名为Docker的卷,并从该容器中的容器中装入数据。 This is the preferred way to do it for Docker. 这是用于Docker的首选方法。

$ docker volume create my-jenkins-volume
$ docker run -d -p 8080:8080 -v my-jenkins-volume:/var/jenkins_home/ -p 5000:5000 jenkins/jenkins

Now you can delete your container and the data will still exist in the volume. 现在,您可以删除容器,数据仍将存在于该卷中。 You can start your container again with the same command and all your previous configurations will be loaded. 您可以使用相同的命令再次启动容器,所有先前的配置都将被加载。

If you want to "save" you changes inside a new image you can use docker commit but this is often not the preferred way to get things done. 如果要“保存”,请在新映像中进行更改,可以使用docker commit,但这通常不是完成任务的首选方法。

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

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