Currently, I'm learning Docker with original documentation from https://docs.docker.com
I got this Permission denied error when perform this step: https://docs.docker.com/get-started/06_bind_mounts/
My command is:
docker run -dp 3000:3000 \
-w /app -v "$(pwd):/app" \
node:12-alpine \
sh -c "yarn install && yarn run dev"
The following error:
yarn install v1.22.18
Error: EACCES: permission denied, open '/app/package.json'
at Object.openSync (fs.js:462:3)
at Object.readFileSync (fs.js:364:35)
at onUnexpectedError (/opt/yarn-v1.22.18/lib/cli.js:88608:106)
at /opt/yarn-v1.22.18/lib/cli.js:88727:9
I googled this error but there is no result yet. Please help me, thank you very much.
Related
I'm running a cypress test in a Docker container with the DockerFile below and my code is throwing the error:
#12 0.662 /bin/sh: 1: $[npm,: not found
I searched previous post about similar error, but I couldn't find any answer to my problem. How can I fix the issue?
DockerFile:
FROM cypress/base:16.13.0
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN npm install
RUN $(npm bin)/cypress verify
RUN $["npm", "run", "cypress:e2e"]
.dockerignore:
node_modules
You must install npm to use npm. so you could do this
RUN apt install sudo curl
RUN curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
then you can use npm after this
I have a Jenkinsfile that looks like
pipeline {
agent {
docker {
image 'myartifactory/cloud-eng/sls-build:0.13'
label 'docker'
registryUrl 'https://myartifactory'
registryCredentialsId 'artfifactory-cred-id'
}
}
environment {
}
stages {
stage('Test') {
sh "env | sort"
sh "make setup-ci"
sh "make test"
}
}
}
When I run this I see that jenkins executed a command that looks like:
docker run -t -d -u 1318244366:1318464184 -w /jenkins_home/jenkins-rh7-a01/8b13f8c3/workspace/te_csoe-1624-switch-shared-https -v /jenkins_home/jenkins-rh7-a01/8b13f8c3/workspace/te_csoe-1624-switch-shared-https:/jenkins_home/jenkins-rh7-a01/8b13f8c3/workspace/te_csoe-1624-switch-shared-https:rw,z -v /jenkins_home/jenkins-rh7-a01/8b13f8c3/workspace/te_csoe-1624-switch-shared-https#tmp:/jenkins_home/jenkins-rh7-a01/8b13f8c3/workspace/te_csoe-1624-switch-shared-https#tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** myartifactory/cloud-eng/sls-build:0.13 cat
This project uses python, NPM, and the serverless framework (javascript).
If I run this as above it will fail
npm ERR! correctMkdir failed to make directory /.npm/_locks
2021-03-11 16:17:02 npm ERR! code EACCES
2021-03-11 16:17:02 npm ERR! syscall mkdir
2021-03-11 16:17:02 npm ERR! path /.npm
2021-03-11 16:17:02 npm ERR! errno -13
2021-03-11 16:17:02 npm ERR!
2021-03-11 16:17:02 npm ERR! Your cache folder contains root-owned files, due to a bug in
2021-03-11 16:17:02 npm ERR! previous versions of npm which has since been addressed.
2021-03-11 16:17:02 npm ERR!
2021-03-11 16:17:02 npm ERR! To permanently fix this problem, please run:
2021-03-11 16:17:02 npm ERR! sudo chown -R 1318244366:1318464184 "/.npm"
2021-03-11 16:17:02 make: *** [setup-ci] Error 243
I tried many solutions with varying success. If I add this:
args '-u root' to the docker section it works as of course root has permissions to everything.... however security isn't going to like running the docker container as root.
No matter what I do with overriding $HOME in environment or args, changing users I always end up with permissions issues either with NPMs or python.
Other errors I've encountered with various hacks such as args '-e HOME=/tmp -e NPM_CONFIG_PREFIX=/tmp/.npm'
../../../../../tmp/.local/share/virtualenvs/te_csoe-1624-switch-shared-https-y_ilovXz/lib/python3.8/site-packages/_pytest/cacheprovider.py:428
2021-03-11 14:45:14 /tmp/.local/share/virtualenvs/te_csoe-1624-switch-shared-https-y_ilovXz/lib/python3.8/site-packages/_pytest/cacheprovider.py:428: PytestCacheWarning: cache could not write path /jenkins_home/jenkins-rh7-a01/8b13f8c3/workspace/te_csoe-1624-switch-shared-https/.pytest_cache/v/cache/nodeids
2021-03-11 14:45:14 config.cache.set("cache/nodeids", sorted(self.cached_nodeids))
Error: EACCES: permission denied, unlink '/jenkins_home/jenkins-rh7-a01/8b13f8c3/workspace/te_csoe-1624-switch-shared-https/.serverless/cloudformation-template-update-stack.json'
2021-03-11 14:45:19 at Object.unlinkSync (fs.js:1136:3)
Since jenkins mounts random directories to share and random users I am not sure how to modify the Dockerfile for the image to grant write permissions....
Does anyone know how to get the permissions correct?
EDIT added Dockerfile
FROM amazonlinux:2
RUN yum install -y amazon-linux-extras
RUN yum install -y unzip
RUN yum groupinstall -y "Development Tools"
RUN yum install vim-enhanced -y
# install python/pipenv
ENV PYTHON_VERSION=3.9
RUN amazon-linux-extras install python${PYTHON_VERSION}
RUN /bin/pip-${PYTHON_VERSION} install pipenv
# install node/npm
RUN curl -sL https://rpm.nodesource.com/setup_12.x | bash -
RUN yum install -y nodejs
RUN mkdir /tmp/node-cache
RUN npm config set cache /tmp/node-cache --global
# install aws-cli2
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
./aws/install && \
rm -rf awscliv2.zip
`
# install vault client
ENV VAULT_VERSION=1.5.4
RUN curl -sSLo /tmp/vault.zip https://releases.hashicorp.com/vault/$VAULT_VERSION/vault_${VAULT_VERSION}_linux_amd64.zip && \
unzip -d /bin /tmp/vault.zip && \
rm -rf /tmp/vault.zip && \
setcap cap_ipc_lock= /bin/vault
ADD ./aws-login.sh /usr/local/bin/aws-login.sh
ADD ./ghe-token.sh /usr/local/bin/ghe-token.sh
ENV PATH="/bin:${PATH}"
# indicates CI CONTAINER so processes can check if running in CI
ENV CI_CONTAINER=1
ENV LANG="en_US.UTF-8"
ENV TERM xterm
# avoid million NPM install messages
ENV npm_config_loglevel warn
ENTRYPOINT []
The thing that was tripping me up was I had run this as -u root many times and I only have one agent (don't ask) and jenkins caches the workspace directory. So the file permissions had been changed in that code by the docker container running as root. So when I got rid of -u root and it started using the jenkins user it didn't have rights to some files and directories.
The solution was to delete the workspace and make sure that all make calls had an export HOME=${WORKSPACE} before any command.
There might be a better way to export HOME but this solves the prob
I am trying to build my container for a root user and then run it with my user and source the /root/.zshrc from inside.
Here is a minimal example:
FROM ubuntu:20.04
RUN apt update
RUN apt install --assume-yes --fix-broken \
curl \
wget \
zsh
RUN echo EDITOR=vim >> /root/.zshrc
RUN chmod a+rx /root
CMD [ "source /root/.zshrc", "zsh"]
The invocation is as follows:
docker run --rm -it -v "$HOME/.ssh:$HOME/.ssh:ro" -v "$HOME/.netrc:$HOME/.netrc:ro" -v /etc/passwd:/etc/passwd:ro -v /etc/shadow:/etc/shadow:ro -v /etc/group:/etc/group:ro --user $UID:$UID foo_minimal
The error that I'm getting is:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"source /root/.zshrc\": stat source /root/.zshrc: no such file or directory": unknown.
What could be the problem here?
I am running docker on windows 10. When I run this command without the -v flag to mount the host drive and file path to the container path, then the container runs fine and I can connect to it. However, when I provide the flag to mount the paths the container exits immediately. This is my command which runs without any error
docker container run -v c:/container-fs:/usr/src/app --publish 8001:8080 --detach --name bboard-ubuntu bulletinboard:Ubuntu
when I run the command docker container ls --all, I see that the container named bboard-ubuntu has exited almost immediately after it started up.
When trying to exec into the container using the command docker exec -it bboard-ubuntu /bin/bash, I get the error message as below:
Error response from daemon: Container
26a2d3361dfc0c890xxxxxxxxxxxxxxx97be532ab6e8771652e5b is not running
When I remove the mount flags and run it like this below, there are no issues and I can exec into the container file system.
docker container run --publish 8001:8080 --detach --name bboard-ubuntu bulletinboard:Ubuntu
How do I trace and fix this issue caused by providing the mount flag?
Edit
This is the Dockerfile
FROM ubuntu:18.04
WORKDIR /usr/src/app
COPY package.json .
# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get update \
&& apt-get install -y curl \
&& apt-get -y autoclean
RUN apt-get install -y apt-utils
RUN apt-get -y install nano
# nvm environment variables
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 13.9.0
# install nvm
# https://github.com/creationix/nvm#install-script
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash
# install node and npm
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
# confirm installation
RUN node -v
RUN npm -v
RUN npm install
EXPOSE 8080
CMD [ "npm", "start" ]
COPY . .
Here is the error after removing detach
npm ERR! code ENOENT npm ERR! syscall open npm ERR! path
/usr/src/app/package.json npm ERR! errno -2 npm ERR! enoent ENOENT: no
such file or directory, open '/usr/src/app/package.json' npm ERR!
enoent This is related to npm not being able to find a file. npm ERR!
enoent
npm ERR! A complete log of this run can be found in: npm ERR!
/root/.npm/_logs/2020-02-26T19_02_33_143Z-debug.log
I am running these commands on windows host. Where do I find the /root/.npm/ log folder?
I'm trying to install docker-machine following the guide.
$ curl -L https://github.com/docker/machine/releases/download/v0.8.2/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine && \
> chmod +x /usr/local/bin/docker-machine
Error:
bash: /usr/local/bin/docker-machine: Permission denied
Why? How can resolve this?
I'm on Xubuntu 16.04.
This is discussed in issue 652
Either you chown that folder
sudo chown -R $(whoami) /usr/local/bin
Or (better), as in this PR
Note: If you get a "Permission denied" error, your /usr/local/bin directory probably isn't writable and you'll need to install Compose as the superuser.
Run sudo -i, then the two commands above, then exit.