I use a mounted kubernetes pvc and i need to move binary conf directory inside this pvc
so i try in my dockerfile to move files using the mv command like follow but when i have the error /apps/files/conf not such file or directory in the logs of my pod (pod created using the build image). I have the same error when i try to move a file testy.txt to PVC files
RUN mv /apps/conf /apps/files/conf
RUN ln -s apps/files/conf /apps/conf
Thank you for your help.
Related
I'm very new to a Docker. I want to copy a local directory to a Docker container but I get error
file not found in build context or excluded by .dockerignore: stat
~/.ssh: file does not exist
Here is the line of COPY code,
COPY ~/.ssh /root/.ssh
I can make sure that I have ~/.ssh that it says dose not exist
I need to do this my Application throw error
java.io.FileNotFoundException: /root/.ssh/id_rsa (No such file or
directory)
Then I've just realised that I need to copy it into a container.
In my app, I need to use id_rsa and known_hosts to connect to a SFTP server.
Please help. Thanks a lot !
As I know, you can only use files from the directory where your Dockerfile is.
You cannot ADD or COPY files outside of the path local to the Dockerfile.
The solution is either mount volume with docker run or docker-compose (what you did already), or copy the directory ~/.ssh/ into your Dockerfile directory and then run docker build again.
Let's say we're in /home/saeed/docker/ where your Dockerfile is located, and it has the following contents:
FROM nginx:alpine
COPY .ssh /root/.ssh
Before running docker build, copy the required directory into the build directory:
cp -r ~/.ssh .
Then you can build and run your image as normal.
I have not found the reason yet but I found the workaround by mounting the volume in docker-compose instead.
- ~/.ssh:/root/.ssh
But if someone could find the solution to my COPY problem I'm willing to learn it!
I am using COPY command in my docker file on top of ubuntu 16.04. I am getting error as no such file or directory eventhough the directory is present. In the below docker file I want to copy the directory "auth" present inside workspace directory to the docker image (at path /home/ubuntu) and then build the image.
FROM ubuntu:16.04
RUN apt-get update
COPY /home/ubuntu/authentication/workspace /home/ubuntu
WORKDIR /home/ubuntu/auth
a Dockerfile COPY command can only refer to files under the context - the current location of the Dockerfile, aka .
so you have a few options now:
if it is possible to copy the /home/ubuntu/authentication/workspace/ directory content to somewhere inside your project before the build (so now it will be included in your Dockerfile context and you can access it via COPY ./path/to/content /home/ubuntu) it can be great. but sometimes you dont want it.
instead of copying the directory, bind it to your container via a volume:
when you run the container, add a -v option:
docker run [....] -v /home/ubuntu/authentication/workspace:/home/ubuntu [...]
mind that a volume is designed so any change you made inside the container dir(/home/ubuntu) will affect the bound directory on your host side (/home/ubuntu/authentication/workspace) and vice versa.
i found a something over here: this guy is forcing the Dockerfile to accept his context- he is sitting inside the /home/ubuntu/authentication/workspace/ directory, and running there
docker build . -f /path/to/Dockerfile
so now inside his Dockerfile he can refer to /home/ubuntu/authentication/workspace as his context (.)
I have a project which is Maven based multi module project
It has various modules with in, like common-utils, web, theme, etc, etc
And also in the root location it has the Dockerfile which is not default one but I have named it Dockerfile.cli due to some requirements
Dockerfile.cli contents here:-
FROM tomcat
ENV NEUW_LOG_HOME /neuw/web/logs
RUN echo "running the image, making it a container :-)"
RUN mkdir -p "/neuw/web/theme-v4"
COPY web/target/web.war /usr/local/tomcat/webapps/ROOT.war
COPY theme-v4 /neuw/web/theme-v4
CMD ["catalina.sh", "jpda", "run"]
Now why I am here -> am getting the below error while building the image:-
COPY failed: stat /var/lib/docker/tmp/docker-builder838877607/web/target/web.war: no such file or directory
The command I use to run the image build is like below and running it on the root of the project which contains both theme and web folder:-
docker build -f Dockerfile.cli -t neuw/web:snapshot-30 .
Any hints and help for the issue?
Which directory are you in when you run this command? Could you do ls /web/target/ from that directory? I ask because I think your Dockerfile is expecting to find a web.war in ./web/target relative to the directory you are running in.
Edit (to save anyone digging through the comments on this): The target directory did contain the file but it was invisible to docker due to a .dockerignore file with **/target.
I have branched both the node red git repo and the node red docker image and am trying to modify the settings.js file to enable Projects Functionality. The settings file that ends up in the Docker Container does not seem to be my modified one. My aim is to use the Docker image in a Cloud Foundry environment.
https://github.com/andrewcgaitskellhs2/node-red-docker.git
https://github.com/andrewcgaitskellhs2/node-red.git
I am also trying to install git and ssh-keygen at the time of the Docker build to allow Projects to function. I have added these in the Package.json files for both the node red app and image git repos.
If I need to start from scratch, please let me know what steps I need take.
I would welcome guidance on this.
Thank you.
You should not be trying to install ssh-keygen and git via the package.json file.
You need to use the Node-RED Dockerfile as the base to build a new Docker container, in the Dockerfile you should use apt-get to install them and to include an edited version of the settings.js Something like this:
FROM nodered/node-red-docker
RUN apt-get install git ssh-client
COPY settings.js /data
ENV FLOWS=flows.json
ENV NODE_PATH=/usr/src/node-red/node_modules:/data/node_modules
CMD ["npm", "start", "--", "--userDir", "/data"]
Where settings.js is your edited version that is in the same directory as the Dockerfile
Edited following #knolleary's comment:
FROM nodered/node-red-docker
COPY settings.js /data
ENV FLOWS=flows.json
ENV NODE_PATH=/usr/src/node-red/node_modules:/data/node_modules
CMD ["npm", "start", "--", "--userDir", "/data"]
It is not necessary to change the image. For persistence, you will mount a host directory into the container at /data, e.g. like this:
docker run --rm -d -v /my/node/red/data:/data -p 1880:1880 nodered/node-red
A settings.js file will get created in your data directory, here /my/node/red/data. Edit this file to enable projects, then restart the container.
It is also possible to place a settings.js file with projects enabled into the directory that you mount to /data inside the container before the first start.
When creating a container using docker run, is there a way to automatically copy files from a docker volume to the host directory it is mounted on?
When running
docker run -d -v /localpath:containerpath image
the files found in containerpath are not copied to my /localpath directory.
Is there a way to achieve this? The image contains a directory that needs to be accessible on the host machine for local development.
What i did not know was that when adding a file to a volume from the shell of the container, it is also created in the host directory. So after a lot of debugging and testing things i have managed to achieve what i wanted
For clarification if anyone needs this in the future: to automatically generate a docker container that clones a git repo and expose the host public_html directory to a volume with the files already copied to the host ready for editing
# Create Volume for the directory
VOLUME /var/www/html
COPY scripts/start.sh /start.sh
RUN chmod -v +x /start.sh
CMD ["/start.sh"]
start.sh contains the code to clone the repo if the directory is empty
#!/bin/bash
if [ "$(ls -A /var/www/html)" ]; then
echo "Directory already cloned"
else
echo "Repo files do not exist" ;
git clone ...
fi
Thanks for the help