Not able to mount -v in the run command - docker

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.

Related

Mounted Docker Volumes Are Empty

Problem
The $(pwd)/app directory locally contains many subdirectories and files. So does the directory in my Docker image /usr/local/app. When I run the following
docker run -it --rm -v $(pwd)/app:/usr/local/app my_image bash
the command is successful, but the /usr/local/app directory is now empty. It seems that I've mounted something to this location, but it's empty.
Is there something that I'm missing here that I should be aware of?
Context
This exact command used to succeed. The only recent change is that I uninstalled Docker Desktop in favor of just using the Docker Engine running on a local minikube instance. I'm using Docker version 20.10.22, build 3a2c30b63a on MacOS Ventura.

Running docker within docker missing file - docker run -v /var/jenkins_home/job:/build ./script.sh

I have Jenkins running in docker container. In Jenkins container we also run docker commands from pipelines. The problem with it is that when we run this from pipeline:
docker run -v /var/jenkins_home/job:/build ./script.sh
It does not mount the content of /var/jenkins_home/job
So I tested it with:
docker run -v /tmp:/build ./script.sh
And it mounted /tmp of the host machine not of Jenkins docker.
What causes this behaviour and how can I mount the path of Jenkins docker not host machine? OR is there anyway to make docker interpret /var/jenkins_home/job to host folder automatically?

Volume not mounting properly when running shell inside a container

I want to encrypt my Kubernetes file to integrate it with Travis CI and for that, I am installing Travis CI CLI via docker container. When the container runs and I mount my current working directory to /app It just creates an empty folder.
I have added the folder in shared folders as well in the Virtual Box but nothing seems to work. I am using Docker Toolbox on Windows 10 home.
docker run -it -v ${pwd}:/app ruby:2.3 sh
It creates the empty app folder along with the other folders in the container but does not mount the volumes.
I also tried using
docker run -it -v //c/complex:/app ruby:2.3 sh
as someone suggested to use the name you specify in the Virtual Box.
Docker run -it -v full path of current directory:/app ruby:2

How to copy SSH from JENKINS host into a DOCKER container?

I can't copy the file from the host into the container using the Dockerfile, because i'm simply not allowed to, as mentioned in Docker Documentation:
The path must be inside the context of the build; you cannot
COPY ../something /something, because the first step of a docker build
is to send the context directory (and subdirectories) to the docker
daemon.
I'm also unable to do so from inside jenkins job, because the job commands run inside the shell of the docker container, there is not way to talk to the parent(which is the jenkins host).
This jenkins plugin could have been a life saver, but as mentioned in the first section: distribution of this plugin has been suspended due to unresolved security vulnerabilities.
This is how I copy files from host to docker image using Dockerfile
I have a folder called tomcat
Inside that, I have a tar file and Dockerfile
Commands to do the whole process just for understanding
$ pwd
/home/user/Documents/dockerfiles/tomcat/
$ ls
apache-tomcat-7.0.84.tar.gz Dockerfile
Sample Docker file:
FROM ubuntu_docker
COPY apache-tomcat-7.0.84.tar.gz /home/test/
...
Docker commands:
$ docker build -it testserver .
$ docker run -itd --name test1 testserver
$ docker exec -it bash
Now you are inside docker container
# ls
apache-tomcat-7.0.84.tar.gz
As you can see I am able to copy apache-tomcat-7.0.84.tar.gz from host to Docker container.
Notice the Docker Documentation first line which you have shared
The path must be inside the context of the build;
So as long as the path is reachable during build you can copy.
Another way of doing this would be using volume
docker run -itd -v $(pwd)/somefolder:/home/test --name test1 testserver
Notice -v parameter
You are telling Docker to mount Current_Directory/somefolder to Docker's path at /home/test
Once the container is up and running you can simply copy any file to $(pwd)/somefolder and it will get copied
inside container at /home/test

Create a volume in docker from windows host

I have the following folder on my windows host
C:\Tmp\TmpVolume
"TmpVolume" has a number of files.
This is where I will be putting my sourcecode for development purposes on the host machine.
Now I want to run the container and mount this folder onto the container. This is the command I execute
docker run -p 49160:3000 -v C:/Tmp/TmpVolume/:/usr/src/app/TmpVolume -d containerName
My problem is that when I move into the directory /usr/src/app in the container there is a TmpVolume folder but this empty, there is nothing inside it. What am I doing wrong here?

Resources