I am receiving a permission error when attempting to map volumes over. I don't understand because I should be root by default as far as I know. I tried chmodding the files 777 on my host but no effect.
client_1 |
client_1 | > web
client_1 | > expo start --web
client_1 |
client_1 | Uncaught Error Error: EACCES: permission denied, mkdir '/root/.expo'
arglasses_client_1 exited with code 1
# pull base image
FROM node:14
# set our node environment, either development or production
ARG NODE_ENV=development
ENV NODE_ENV $NODE_ENV
# default to port 19006 for node, and 19001 and 19002 (tests) for debug
ARG PORT=19006
ENV PORT $PORT
EXPOSE $PORT 19001 19002
# install global packages
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH /home/node/.npm-global/bin:$PATH
RUN npm i --unsafe-perm -g npm#latest expo-cli#latest
# install dependencies first, in a different location for easier app bind mounting for local development
RUN mkdir /opt/client
WORKDIR /opt/client
ENV PATH /opt/client/.bin:$PATH
# copy in our source code last, as it changes the most
WORKDIR /opt/client/app
# for development, we bind mount volumes; comment out for production
COPY . .
RUN npm install
ENTRYPOINT ["npm", "run"]
CMD ["web"]
services:
client:
build: client
environment:
- NODE_ENV=development
tty: true
ports:
- '19006:19006'
- '19001:19001'
- '19002:19002'
depends_on:
- server
volumes:
- ./client:/opt/client/app
- /opt/client/app/node_modules
Related
Trying to sort this permission error on Ubuntu, when trying to run my containers using dockerfile and docker-compose.yml
Exiting
/usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:433:in `initialize': Permission denied # rb_sysopen - /home/api/limpar/current/tmp/pids/server.pid (Errno::EACCES)
Dockerfile
FROM ruby:2.7.1
ENV LANG C.UTF-8
ENV NODE_VERSION 12
ENV NODE_ENV production
ENV INSTALL_PATH /home/api/limpar/current
.
(...)
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY Gemfile Gemfile.lock ./
RUN gem install bundler
RUN bundle install
COPY . $INSTALL_PATH
RUN rm -rf tmp
RUN useradd -Ms /bin/bash api -u 1001
RUN chown -R api:api /home/api /usr/local/bundle
USER api
EXPOSE 3000
CMD rails server -p 3000 -b 0.0.0.0
docker-compose.yml
api:
container_name: limpar-api
image: limpar-api
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
env_file:
- .env
volumes:
- ./:/home/api/limpar/current
ports:
- "3000:3000"
depends_on:
- db
- redis
networks:
- limpar_network
docker build runs with no failures. Dockerfile instal_path overwrites a volume location on docker-compose file. By changing the volume name on my docker-compose.yml file,
I am able to fix the permission errors.
However, the local changes on my code no longer get reflected, meaning I have to rebuild everytime I change anything.
Any missing points on Dockerfile, regarding user permissions?
Thanks in advance
Adding
USER root
to Docker file, RUN chown... fixed the permission issues, and allowed me to keep same path on dockerfile and docker-compose volume, solving the local code changes not reflecting.
I have a laravel project that runs on a single docker container.
I use docker-composer.yml to configure the container. I use nginx:latest base image in my Dockerfile. For some reason when I tried to launch my project with command docker-compose up I got this error:
web_1 | 2019-05-10 15:51:14,035 INFO spawnerr: can't find command '/usr/sbin/nginx'
web_1 | 2019-05-10 15:51:15,037 INFO spawnerr: can't find command '/usr/sbin/nginx'
web_1 | 2019-05-10 15:51:17,040 INFO spawnerr: can't find command '/usr/sbin/nginx'
web_1 | 2019-05-10 15:51:20,050 INFO spawnerr: can't find command '/usr/sbin/nginx'
web_1 | 2019-05-10 15:51:20,050 INFO gave up: nginx entered FATAL state, too many start retries too quickly
I was suprised so I took a look inside the container with docker exec -ti mycontainername bash and I couldn't find nginx anywhere. I tried with nginx -v,
whereis nginx , cd /etc/nginx <-- directory didn't exist.
So i tried to create a simple container, which containts only nginx. I should theoretically be able to go to localhost:80 and see the Nginx welcome message, right?
docker run --rm -d -p 80:80 --name my-nginx nginx
well there was no message and when I took a look inside the container
docker exec my-nginx I couldn't find nginx anywhere, but if I ran the command apt-get nginx it showed that nginx is already the latest version.
FULL DOCKER-COMPOSE.YML
version: '1'
services:
web:
build:
context: ./
# dockerfile: web.dockerfile
working_dir: /var/www/html
# volumes_from:
# - app
ports:
- 8080:80
volumes:
- ./:/var/www/html
- /var/run/docker.sock:/var/run/docker.sock
environment:
full Dockerfile:
FROM nginx:latest
RUN apt-get update && apt-get install -y php-gd
RUN apt-get -y install php7.2-zip
#COPY app /var/www/html/app
#COPY artisan /var/www/html/app/artisan
#COPY bootstrap /var/www/html/bootstrap
#COPY config /var/www/html/config
#COPY database /var/www/html/database
#COPY public /var/www/html/public
#COPY resources /var/www/html/resources
#COPY routes /var/www/html/routes
#COPY storage /var/www/html/storage
#COPY vendor /var/www/html/vendor
#COPY artisan /var/www/html/artisan
#COPY composer.json /var/www/html/composer.json
COPY entrypointcust.sh /entrypointcust.sh
RUN chmod +x /entrypointcust.sh
EXPOSE 80
WORKDIR /var/www/html/old
# Add crontab file in the cron directory
ADD cron /etc/cron.d/appcron
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/appcron
RUN /usr/bin/crontab /etc/cron.d/appcron
# Create the log file to be able to run tail
#RUN touch /var/log/cron.log
#RUN touch /var/www/html/storage/logs/laravel.log
#RUN chown -R www-data:www-data /var/www/html
#RUN chmod -R 777 /var/www/html/storage
ENTRYPOINT ["/bin/bash", "-c", "/entrypointcust.sh"]
What am I missing?
I dockerized my mean application with docker-compose. This works fine.
Now I try to use "volumes" so that my angular app (with ng serve) and my express app (with nodemon.js) auto-restart when coding.
But identical error appears for both angular and express container :
angular_1 |
angular_1 | up to date in 1.587s
angular_1 | found 0 vulnerabilities
angular_1 |
angular_1 | npm ERR! path /usr/src/app/package.json
angular_1 | npm ERR! code ENOENT
angular_1 | npm ERR! errno -2
angular_1 | npm ERR! syscall open
angular_1 | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
angular_1 | npm ERR! enoent This is related to npm not being able to find a file.
angular_1 | npm ERR! enoent
angular_1 |
angular_1 | npm ERR! A complete log of this run can be found in:
angular_1 | npm ERR! /root/.npm/_logs/2019-04-07T20_51_38_933Z-debug.log
harmonie_angular_1 exited with code 254
See my folder hierarchy :
-project
-client
-Dockerfile
-package.json
-server
-Dockerfile
-package.json
-docker-compose.yml
Here's my Dockerfile for angular :
# Create image based on the official Node 10 image from dockerhub
FROM node:10
# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app
# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app
# Copy dependency definitions
COPY package*.json /usr/src/app/
# Install dependecies
RUN npm install
# Get all the code needed to run the app
COPY . /usr/src/app/
# Expose the port the app runs in
EXPOSE 4200
# Serve the app
CMD ["npm", "start"]
My Dockerfile for express :
# Create image based on the official Node 6 image from the dockerhub
FROM node:6
# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app
# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app
# Copy dependency definitions
COPY package*.json /usr/src/app/
# Install dependecies
RUN npm install
# Get all the code needed to run the app
COPY . /usr/src/app/
# Expose the port the app runs in
EXPOSE 3000
# Serve the app
CMD ["npm", "start"]
And finally my docker-compose.yml
version: '3' # specify docker-compose version
# Define the services/containers to be run
services:
angular: # name of the first service
build: client # specify the directory of the Dockerfile
ports:
- "4200:4200" # specify port forwarding
#WHEN ADDING VOLUMES, ERROR APPEARS!!!!!!
volumes:
- ./client:/usr/src/app
express: #name of the second service
build: server # specify the directory of the Dockerfile
ports:
- "3000:3000" #specify ports forwarding
links:
- database
#WHEN ADDING VOLUMES, ERROR APPEARS!!!!!!
volumes:
- ./server:/usr/src/app
database: # name of the third service
image: mongo # specify image to build container from
ports:
- "27017:27017" # specify port forwarding
I also had this error, it turned out to be an issue with my version of docker-compose. I'm running WSL on windows 10 and the version of docker-compose installed inside WSL did not handle volume binding correctly. I fixed this by removing /usr/local/bin/docker-compose and then adding an alias to the windows docker-compose executable alias docker-compose="/mnt/c/Program\ Files/Docker/Docker/resources/bin/docker-compose.exe"
If The above does not apply to you then try to update your version of docker-compose
you volumes section should look like this:
volumes:
- .:/usr/app
- /usr/app/node_modules
after mounting source folder node_modules in Docker container is 'overwritten' so you need to add the '/usr/app/node_modules'. Full tutorial with proper docker-compose.yml - https://all4developer.blogspot.com/2019/01/docker-and-nodemodules.html
I need to install other node.js modules on the bitnami docker container.
I would like to install body-parser module to the container. I've started the container with sudo docker-compose up and it runs fine. i tried to modify the dockerfile and docker-compose.yml file to install the body-parser but i get EACCES permission denied, access '/app/node_modules' error. Can you help?
TIA,
Thomas
**** UPDATE 4/23/2019 ***
This is the docker file.
I added body-parser line.
## Dockerfile for building production image
FROM bitnami/express:4.16.4-debian-9-r166
LABEL maintainer "John Smith <john.smith#acme.com>"
ENV DISABLE_WELCOME_MESSAGE=1
ENV NODE_ENV=production \
PORT=3000
# Skip fetching dependencies and database migrations for production image
ENV SKIP_DB_WAIT=0 \
SKIP_DB_MIGRATION=1 \
SKIP_NPM_INSTALL=1 \
SKIP_BOWER_INSTALL=1
COPY . /app
RUN sudo chown -R bitnami: /app
RUN npm install
RUN npm install --save body-parser
EXPOSE 3000
CMD ["npm", "start"]
docker-compose.yml
version: '2'
services:
mongodb:
image: 'bitnami/mongodb:latest'
express:
tty: true # Enables debugging capabilities when attached to this container.
image: 'bitnami/express:4'
command: npm start
environment:
- PORT=3000
- NODE_ENV=development
- DATABASE_URL=mongodb://mongodb:27017/myapp
- SKIP_DB_WAIT=0
- SKIP_DB_MIGRATION=0
- SKIP_NPM_INSTALL=0
- SKIP_BOWER_INSTALL=0
depends_on:
- mongodb
ports:
- 3000:3000
volumes:
- .:/app
I'm trying to build docker-compose, but I'm getting this error:
ERROR: for indicaaquicombrold_mysqld_1 Cannot start service mysqld:
oci runtime error: container_linux.go:247: starting container process
caused "exec: \"/docker-entrypoint.sh\": permission denied"
ERROR: for mysqld Cannot start service mysqld: oci runtime error:
container_linux.go:247: starting container process caused "exec:
\"/docker-entrypoint.sh\": permission denied"
ERROR: Encountered errors while bringing up the project.
docker-compose.yml
version: '3'
services:
php:
build:
context: ./docker/php
image: indicaaqui.com.br:tag
volumes:
- ./src:/var/www/html/
- ./config/apache-config.conf:/etc/apache2/sites-enabled/000-default.conf
ports:
- "80:80"
- "443:443"
mysqld:
build:
context: ./docker/mysql
environment:
- MYSQL_DATABASE=db_indicaaqui
- MYSQL_USER=indicaqui
- MYSQL_PASSWORD=secret
- MYSQL_ROOT_PASSWORD=docker
volumes:
- ./config/docker-entrypoint.sh:/docker-entrypoint.sh
- ./database/db_indicaaqui.sql:/docker-entrypoint-initdb.d/db_indicaaqui.sql
Dockerfile (php)
FROM php:5.6-apache
MAINTAINER Limup <limup#outlook.com>
CMD [ "php" ]
RUN docker-php-ext-install pdo_mysql
# Enable apache mods.
# RUN a2enmod php5.6
RUN a2enmod rewrite
# Expose apache.
EXPOSE 80
EXPOSE 443
# Use the default production configuration
# RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
# Override with custom opcache settings
# COPY ./../../config/php.ini $PHP_INI_DIR/conf.d/
# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
# Update the PHP.ini file, enable <? ?> tags and quieten logging.
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" "$PHP_INI_DIR/php.ini"
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" "$PHP_INI_DIR/php.ini"
RUN a2dissite 000-default.conf
RUN chmod -R 777 /etc/apache2/sites-enabled/
WORKDIR /var/www/html/
# By default start up apache in the foreground, override with /bin/bash for interative.
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Dockerfile (Mysql)
FROM mariadb:latest
RUN chmod -R 777 /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 3306
CMD ["mysqld"]
Please, help me solve this problem!
Any ideas?
That is most likely a Linux file permission issue on config/docker-entrypoint.sh. If your host is Linux/Mac, you can run:
chmod 755 config/docker-entrypoint.sh
For more on linux permissions, here's a helpful article: https://www.linux.com/learn/understanding-linux-file-permissions
First, you need to copy entrypoint.sh file into other directory instead of same your source code (Eg. /home/entrypoint.sh), then grant permission to execute entrypoint script:
RUN ["chmod", "+x", "/home/entrypoint.sh"]
Solution
ENV USER root
ENV WORK_DIR_PATH /home
RUN mkdir -p $WORK_DIR_PATH && chown -R $USER:$USER $WORK_DIR_PATH
WORKDIR $WORK_DIR_PATH
Info
The USER instruction sets the user name (or UID) and optionally the user group (or GID) to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.
The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn’t exist, it will be created even if it’s not used in any subsequent Dockerfile instruction.
Links
chown command
docker builder reference
A pretty common solution if nothing works is to re-install Docker.. That's what ended up working for me after trying for like 5 hours everything under the sun in terms of permissions etc.