0

I am new to the concept of Docker. In my office server we have installed Docker and running the Jenkins images as containers.

We want to run the below command in the Jenkinsfile in a process to create the Jenkins pipeline.

docker run --rm -p 8080:8080 -v $PWD/app:/opt/app --name=app-server App

The problem is face is the volumes are not mounting in the /opt/app from the $PWD/app (which is the volume of the Jenkins container).

I have app.txt file in the $PWD/app. After running the above command it should present in the /opt/app, but the folder is empty.

Because of this the configuration files are missing in the app-server container volume. Error config files are missing is happening.

What is the reason for this problem. Why the files in the $PWD/app are not mounting to the /opt/app folder?

Point to consider:

docker run command is running in the Jenkins container.

The command on top is running prefect when the jenkins is running locally,not as docker container.

Sai Varun
  • 1
  • 1
  • 1
  • Can you do `docker exec -it app-server bash` in a new terminal, then `cd /opt/app` and then `ls` and let us know what the result is? – 7_R3X Sep 17 '19 at 06:31
  • If this `docker run` is started from inside the container, the `$PWD` is resolved as `/` probably, or `/root` so you are either mounting `/app:/opt/app` or `/root/app:/opt/app` which results in being empty. You can validate this: 1) `docker ps` to get the list of running containers, get its id 2) docker inspect [id_here] then look for `Mounts` – Mike Doe Sep 17 '19 at 06:31
  • The pipeline is executed in the workspace, the mount would be i.e. /path/to/jenkins/workspace/app:/opt/apt - if the “app” folder is in the jenkins users HOME directory then use the $HOME environment variable in the bind mount. – masseyb Sep 17 '19 at 06:32
  • I did docker exec -it app-server bash in a new terminal, then cd /opt/app and then ls. The app folder is empty – Sai Varun Sep 17 '19 at 06:34
  • $PWD is resolved to the volume of the jenkins, which is its workspace. I am mounting from /var/jenkins_home/my_pipeline_job/app:/opt/app – Sai Varun Sep 17 '19 at 06:39
  • try to echo $PWD to ee what comes – LinPy Sep 17 '19 at 06:44
  • try `docker run --rm -p 8080:8080 -v $PWD/app:/opt/app --name=app-server App bash -c "$PWD; ls /opt/app` – Adiii Sep 17 '19 at 07:12
  • Possible duplicate of [How to mount docker volume with jenkins docker container?](https://stackoverflow.com/questions/42946067/how-to-mount-docker-volume-with-jenkins-docker-container) – David Maze Sep 17 '19 at 12:12
  • The root of the issue is that the `docker run -v` option always takes a path on the physical host where Docker is running; you can't mount a folder from one container into another. That question has some workarounds, another option is to use the [`docker.image().inside()` pipeline invocation](https://jenkins.io/doc/book/pipeline/docker/) which will map the workspace directory into the container for you. – David Maze Sep 17 '19 at 12:14

0 Answers0