When inside jenkins,I can mound workspace folder to newly created docker for php

Hi,
I am using jenkins for continue php code deplpyment.
what I use:
1: I mount host docker on jenkins so jenkins directly use my host docker and it can create new docker containers on host machine.
when i create a new docker image by using below command:

 sudo docker run -d -p 8081:80 --name my-apache-php-app -v /var/jenkins_home/workspace/EasyApp/web:/var/www/html php:7.0-apache

/var/jenkins_home/workspace/EasyApp/web is present in jenkins docker.

when i open the newly created docker :my-apache-php-app and check “/var/www/html”, it is empty.

here what is the possibility:
when I user docker it looks to host not current jenkins docker and the source folder is not present on host and nothing is copied to newly created docker.

now I am wondering is there a method so that the docker command pick the source file from jenkins not host?

Regards,
Hikmat

For example, if Jenkins is running inside a container, it would put its own /var/jenkins_home/ directory as host volume: docker run -d --name jenkins -v /var/jenkins_home:/var/jenkins_home ...

Now, any location that refers to /var/jenkins_home, whether it is inside the jenkins container directly, or another container that also refers to /var/jenkins_home, it will be referring to the same location.

2 Likes

To be extremely specific: docker run -v /host:/container causes the directory /host on the physical host (or VM) where the Docker daemon is running to be mounted into the container at /container. If you’re running the docker command somewhere else (from a remote host, from inside a container) then you need to figure out an appropriate path on your own, or come up with some other way to get content into the container.

Since you’re in the context of a CI system anyways, I’d build an image containing the application, run external tests on it, and push it to a registry. docker build will start by copying the local directory over to the Docker host and so avoids these directory mapping problems.

1 Like

This is what I search for 2 days…
The docker-compose didnt work for me inside the Jenkins container, but now it is works perfectly!
Thank you for this! :heart_eyes: