Hi there,
I am not quite sure I post this issue in the correct Category. Whoever has the rights to, feel free to change it if it’s not.
I have an issue regarding permissions with pretty much all the projects I work on, in my team. Here are a few information about it :
- we all work on the same repositories, with the exact same files and I am the only one having this issue.
- we all use an updated version of Docker with Docker Compose plugin.
- we all use 1001:1001 user and group because we’re given computers that already have a preconfig 1000:1000 user that we can’t use. This has been well established in the company and we are not to change it.
- we work on different applications / repositories that are programmed in different languages. The issue happens with every one of them.
- I work on Ubuntu 22.04.2 LTS 64 bits. I tried to uninstall and install Docker again as cleanly as I could yesterday, but still have the same issue.
- my user has been added to the docker group.
- in the given example as pretty much every other project, we mount a volume on the project sources so that we can change and not have to restart the container every time we do.
That being said, here is an example of a Makefile used in these repositories
APP_NAME = app
export DEV_UID = $(shell id -u)
export DEV_GID = $(shell id -g)
DOCKER_COMPOSE = docker compose
DOCKER_BUILD = BUILDKIT=1 $(DOCKER_COMPOSE) build
DOCKER_UP = $(DOCKER_COMPOSE) up -d
DOCKER_DOWN = $(DOCKER_COMPOSE) down
DOCKER_EXEC = $(DOCKER_COMPOSE) run
LOG_FILE = ./var/error.log
APP_ADDRESS = http://localhost:8081/
install: ## Install NodeJS sample App
@$(MAKE) requirements
requirements: build
@$(MAKE) start
@echo "Installing dependencies"
@$(DOCKER_EXEC) $(APP_NAME) npm install
@echo "Installing SQLite migrations"
@$(DOCKER_EXEC) $(APP_NAME) npx prisma migrate dev
build: ## build docker image
$(DOCKER_BUILD)
start: ## start docker image
$(DOCKER_UP)
Here is an example of Dockerfile
FROM node:18 AS core
RUN apt-get update \
&& apt-get install -y \
git \
unzip \
curl \
sqlite3 \
&& apt-get clean
###############################################################################
FROM core AS dev-tools
##Update npm
RUN npm install -g npm
##Install nodemon
RUN npm install -g nodemon
###############################################################################
FROM dev-tools as development
ARG USER=www-data
WORKDIR /srv/app
USER $USER
CMD nodemon
And here is the docker-compose.yml :
version: "3.9"
services:
app:
build:
context: .
target: development
args:
NODE_ENV: local
environment:
- HOME=/tmp
- APP_ENV=${APP_ENV:-dev}
- NODE_ENV=local
volumes:
- "./:/srv/app:rw"
user: "${DEV_UID:-1000}:${DEV_GID:-1000}"
restart: unless-stopped
ports:
- "8081:80"
networks:
- default
networks:
default: ~
Here are my subuid and subgid files :
my-user:0:1000
my-user:1001:65536
company:100000:65536
my-user:0:1000
my-user:1001:65536
company:100000:65536
Still, when executing the make install command, every thing works fine until the requirements need to be installed. When trying to execute composer for php, npm for node or any other dependency manager, or any other command that needs to write files (happens also with sqlite db file creation), I have the following error :
Installing dependencies
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /srv/app/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/srv/app/node_modules'
npm ERR! [Error: EACCES: permission denied, mkdir '/srv/app/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/srv/app/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in: /tmp/.npm/_logs/2023-04-18T07_59_25_826Z-debug-0.log
Also happens when the node_modules / vendor / any other dependency folder is already created.
The only way I can make this work is by deleting the definition of DEV_UID and DEV_GID shell variables in my Makefile. This workaround has worked for a few month but is a bit dangerous as I can’t push it on our repositories with this change and it already incidentally happened a few times because of other changes I had to make for a feature.
Again, this is just an example. The issue is triggered on whatever project I work on that have a similar functioning.
Hopefully someone will be able to help me.