Deviation allowed, mkdir in container when opened

I have a container with nodejs and pm2 as a launch command, and on OpenShift I get this error on startup:

Error: EACCES: permission denied, mkdir '/.pm2'

I tried the same image on the Marathon hoster and it worked fine.

Do I need to change something using UserIds?

Docker File:

FROM node:7.4-alpine

RUN npm install --global yarn pm2

RUN mkdir /src

COPY . /src

WORKDIR /src

RUN yarn install --production

EXPOSE 8100

CMD ["pm2-docker", "start", "--auto-exit", "--env", "production", "process.yml"]

Updating the
image node already creates a new user "node" with UID 1000, so as not to run the image as root.
I also tried to set permissions and add the user “node” to the root group.
Next I said pm2, which it should use with ENV var:

PM2_HOME = / home / node / app / .pm2

But I still get the error:

Error: EACCES: permission denied, mkdir '/home/node/app/.pm2'

Updated docker file:

FROM node:7.4-alpine

RUN npm install --global yarn pm2

RUN adduser node root
COPY . /home/node/app
WORKDIR /home/node/app
RUN chmod -R 755 /home/node/app
RUN chown -R node:node /home/node/app

RUN yarn install --production

EXPOSE 8100

USER 1000

CMD ["pm2-docker", "start", "--auto-exit", "--env", "production", "process.yml"]

Update2 Graham Dumpleton,

FROM node:7.4-alpine

RUN npm install --global yarn pm2

RUN adduser node root
COPY . /home/node/app
WORKDIR /home/node/app

RUN yarn install --production

RUN chmod -R 775 /home/node/app
RUN chown -R node:root /home/node/app

EXPOSE 8100

USER 1000

CMD ["pm2-docker", "start", "--auto-exit", "--env", "production", "process.yml"]
+4
4

OpenShift root. , root. , root, , .

, root.

.

  • UNIX ( uid) USER Dockerfile. .

  • Fixup /src , . , . , , , root.

  • , HOME /src Dockerfile.

, OpenShift uid, root, , , , /src. HOME , , , /src.

+10

, root- , :

oc adm policy add-scc-to-user anyuid -z default

+1

sudo chmod a=rwx -R .

-1

?

"" :

CLI:

oc edit scc restricted 

:

runAsUser:
  type: RunAsUSer

to

runAsUser:
  type: RunAsAny

,

-2

Source: https://habr.com/ru/post/1670388/


All Articles