Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build on a host when running Jenkins inside a Docker container

Tags:

docker

jenkins

I am running a Jenkins instance within a Docker container, and it is connected to a Bitbucket repository. When something changes in the online repository, Jenkins downloads the new source. Based on the new source, I want to create a new Docker image, but that needs to happen on the host since it is where I have Docker installed.

I haven't figured out how can I run something on the host, but at the same time I understand that Docker is used for isolating processes, so this is by design. Is there a way to achieve this?

like image 277
Demetris Avatar asked May 17 '16 08:05

Demetris


People also ask

Can you run Jenkins in a container?

Launch Jenkins in a Docker container. Install additional tools and plugins. Pass Java system properties and Jenkins application arguments. Backup the Docker volume.

Can you develop inside a Docker container?

Developing inside a Docker container generally means starting a container and leaving it running, while you edit your source code. As you make changes, you see the changes appear in the container. To get your source code inside a container, you can use something called a bind mount.

Can we integrate Jenkins with Docker?

Add the Docker plug-in Go to Manage Jenkins -> Plugins -> Available and type “docker” into the field. Select “Docker plugin” and install it. Jenkins refers to the Docker plugin as a “cloud.” Click Manage Jenkins once again, and now click the Manage Clouds and Nodes button in the middle.


1 Answers

I would create a separate Jenkins slave that maps to either the host running Jenkins, or a separate host that has Docker installed. Then run your job to create Docker images on the slave rather than the master.

The documentation for the official Jenkins Docker image has details on how to connect up a slave.

like image 121
gareth_bowles Avatar answered Oct 19 '22 09:10

gareth_bowles