mkdir: cannot create directory '/ffa_app': Permission denied - docker

I am trying to create a Dockerfile for an app which I want to run inside the docker. I am running the app using the command activator run.
and this command is inside the file structure
xyz\Desktop\ffa_predix\activator-1.2.10.
So, I have gone inside the file and put my Dockerfile there with the following content.
FROM jboss/base-jdk:7
RUN mkdir -p /ffa_app
COPY . /ffa_app
WORKDIR /ffa_app
CMD ["activator" , "run"]
EXPOSE 9000
But after going to the second line it's giving me the error:
mkdir: cannot create directory '/ffa_app': Permission denied.

The user set by the base image is jboss, so you have 2 options:
create and work in the user's home folder mkdir -p ~/ffa_app
set USER root at the top of your Dockerfile, after the FROM statement
Needless to say, I'd recommend sticking to a user with lower privileges.

Related

Docker volume file permissions

I have create a docker container with this command:
docker run -d -p 20001:80 -v /home/me/folder1/:/usr/local/apache2/htdocs/ httpd:2.4
This container contains scripts which create files and directories in /usr/local/apache2/htdocs/ folder.
I can see this files on host computer in /home/me/folder1/ folder.
I have tried to open one of this files because i want to write something.
I cannot do that because i do not have write permission on this files. This is because they are owned by root user.
What can i do in order to make this files writable be "me" user ? I want to do that automaticaly
Thanks a lot
you have to do
sudo chmod +x nameofscript.sh
whit this command execute by master you set this scripts executable for all users

Setup different user permissions on files copied in Dockerfile

I have this Dockerfile setup:
FROM node:14.5-buster-slim AS base
WORKDIR /app
FROM base AS production
ENV NODE_ENV=production
RUN chown -R node:node /app
RUN chmod 755 /app
USER node
... other copies
COPY ./scripts/startup-production.sh ./
COPY ./scripts/healthz.sh ./
CMD ["./startup-production.sh"]
The problem I'm facing is that I can't execute ./healthz.sh because it's only executable by the node user. When I commented out the two RUN and the USER commands, I could execute the file just fine. But I want to enforce the executable permissions only to the node for security reasons.
I need the ./healthz.sh to be externally executable by Kubernetes' liveness & rediness probes.
How can I make it so? Folder restructuring or stuff like that are fine with me.
In most cases, you probably want your code to be owned by root, but to be world-readable, and for scripts be world-executable. The Dockerfile COPY directive will copy in a file with its existing permissions from the host system (hidden in the list of bullet points at the end is a note that a file "is copied individually along with its metadata"). So the easiest way to approach this is to make sure the script has the right permissions on the host system:
# mode 0755 is readable and executable by everyone but only writable by owner
chmod 0755 healthz.sh
git commit -am 'make healthz script executable'
Then you can just COPY it in, without any special setup.
# Do not RUN chown or chmod; just
WORKDIR /app
COPY ./scripts/healthz.sh .
# Then when launching the container, specify
USER node
CMD ["./startup-production.sh"]
You should be able to verify this locally by running your container and manually invoking the health-check script
docker run -d --name app the-image
# possibly with a `docker exec -u` option to specify a different user
docker exec app /app/healthz.sh && echo OK
The important thing to check is that the file is world-executable. You can also double-check this by looking at the built container
docker run --rm the-image ls -l /app/healthz.sh
That should print out one line, starting with a permission string -rwxr-xr-x; the last three r-x are the important part. If you can't get the permissions right another way, you can also fix them up in your image build
COPY ./scripts/healthz.sh .
# If you can't make the permissions on the original file right:
RUN chmod 0755 *.sh
You need to modify user Dockerfile CMD command like this : ["sh", "./startup-production.sh"]
This will interpret the script as sh, but it can be dangerous if your script is using bash specific features like [[]] with #!/bin/bash as its first line.
Moreover I would say use ENTRYPOINT here instead of CMD if you want this to run whenever container is up

Create directory in dockerfile failed , permmision

Im trying to create dir in docker file and I got error during the build
FROM circleci/openjdk:8-jdk-browsers
#RUN chown newuser /dep
#USER newuser
RUN mkdir /dep
The error is:
mkdir: cannot create directory ‘/dep’: Permission denied`
The command `/bin/sh -c mkdir -p /dep` returned a non-zero code: 1
even if I try only dep .
I try to use chown without success, any idea ?
This image is run with the user circleci, you can check this by adding a whoami to a RUN statement in your Dockerfile. This user has no permission to create folders in /. So, you can either create a folder somewhere where this user has the necessary rights (e.g. /home/circleci/dep), or you just go with sudo mkdir.

Docker COPY issue while building the docker image

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.

COPY in Dockerfile?

I'm looking for the best way to copy a folder from a localhost to Docker container, then launch bash command inside the container?
I proceed as following instruction inside Dockerfile :
WORKDIR /workspace/
COPY /path_in_localhost /Project
RUN ["/bin/bash", "-c", " cd /workspace/Project/ && make"]
the issue is when Docker come to the last instruction, it can find the folder, it's like the copy doesn't work?
/bin/bash: line 0: cd: /workspace/Project: No such file or directory
any suggestion ?
If you want to take advantage of WORKDIR you need to use relative path, thus specifying Project without the / as destination.

Resources