I want to resolve the docker permission denied error.

Asked 2 years ago, Updated 2 years ago, 99 views

What do you want to solve

I would like to resolve the docker permission denied error.
I'm an introductory programmer.I was thinking of using docker for my portfolio, so I have been learning from youtube videos for about two days.However, in the middle of it,

 failed to solve:rpc error:code=Unknown desc=error from sender:open 
/home/senseiy/Documents/rails_docker/src/db/mysql_data/#innodb_temp:permission denied

I got an error like this and it got stuck here.
I'm using wsl2 of Windows 11 environment.wsl2 uses ubuntu 20.04.

Problems/errors encountered

 senseiy@senseIY:~/Documents/rails_docker $docker-compose run web rails new.--force --database=mysql
[+] Running 13/13
 ⠿ db Pulled 66.9s
   ⠿ 15115158dd02 Pull complete 7.3s
   ⠿ d733f6778b18 Pull complete 7.4s
   ⠿ 1cc7a6c74a04 Pull complete 7.8s
   ⠿ c4364028a805 Pull complete 8.0s
   ⠿ 82887163f0f6 Pull complete 8.1s
   ⠿ 097 bfae26e7a Pull complete 9.8s
   ⠿ e1b044d6a24f Pull complete 9.9s
   ⠿ cd2978bd4d12 Pull complete 10.0s
   ⠿ 28bce 5cc1677 Pull complete 19.8s
   ⠿ 907b6d695760 Pull complete 19.8s
   ⠿ c5049403458b Pull complete 19.9s
   ⠿ f360718d6f4e Pull complete 20.0s
[+] Running 2/2
 ⠿ Network rails_docker_default Created 0.8s
 ⠿ Container rails_docker-db-1 Created 0.5s
[+] Running 1/1
 ⠿ Container rails_docker-db-1 Started 1.6s
[+] Building 73.8s (6/9)
 =>[internal] load build definition from Dockerfile 0.0s
 =>=>transferring dockerfile: 396B 0.0s
 =>[internal] load.dockerignore 0.0s
 =>=>transferring context—2B 0.0s
 =>[internal] load metadata for docker.io/library/ruby:2.7 73.2s
 =>CACHED[1/5] FROM docker.io/library/ruby:2.7 @sha256:490f9343c654ce108a1bd34b4896e531135ffd47b9a25081948770ab90.0s
 =>ERROR [internal] load build context 0.0s
 =>=>transferring context—324B 0.0s
 =>CANCELED [2/5] RUN curl-sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add-&echo"deb https:/0.5s
------
 >[internal] load build context:
------
failed to solve:rpc error:code=Unknown desc=error from sender:open/home/senseiy/Documents/rails_docker/src/db/mysql_data/#innodb_temp:permission denied

Files Used

Dockerfile

#Dockerfile

FROM ruby: 2.7
RUN curl-sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add-\
    &echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee/etc/apt/sources.list.d/yarn.list\
    &apt-get update-qq\
    &apt-get install-y nodejs yarn
WORKDIR/app
COPY./src/app
RUN bundle config --local set path 'vendor/bundle'\
    & bundle install

Gemfile

source 'https://rubygems.org'

gem 'rails', '~>6.1.0'

docker-compose.yml

version: '3'
services:
  db: 
    image:mysql:8.0
    command:--default-authentication-plugin=mysql_native_password
    volumes: 
      - ./src/db/mysql_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD:password
  web:
    build:.
    command: bundle exec rails -p 3000-b '0.0.0.0'
    volumes: 
      - ./src:/app
    ports:
      - "3000:3000"
    depend_on:
      - db

Tries and considerations

·I checked for spelling errors, but there seemed to be no problem.
·https://teratail.com/questions/356474
Using this article as a reference, move the Dockerfile to ./build/web/Dockerfile and use the web: in docker-compose.yml

web:
    build:./build/web

If you change to and delete the COPY part of the Dockerfile and then run it

 senseiy@senseIY:~/Documents/rails_docker $docker-compose run web rails new.--force --database=mysql
[+] Running 1/0
 ⠿ Container rails_docker-db-1 Running 0.0s
[+] Building 43.3s (7/7) FINISHED
 =>[internal] load build definition from Dockerfile 0.0s
 =>=>transferring dockerfile:399B 0.0s
 =>[internal] load.dockerignore 0.0s
 =>=>transferring context—2B 0.0s
 =>[internal] load metadata for docker.io/library/ruby:2.7 41.3s
 =>[1/4] FROM docker.io/library/ruby:2.7 @sha256:490f9343c654ce108a1bd34b4896e5311350.0s
 = > CACHED [2/4] RUN curl-sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add 0.0s
 =>CACHED [3/4] WORKDIR/app 0.0s
 =>ERROR [4/4] RUN bundle config -- local set path 'vendor/bundle' & bundle ins 1.9s
------
 >[4/4] RUN bundle config -- local set path 'vendor/bundle' & bundle install:
#7 1.857 Could not locate Gemfile
------
failed to solve:rpc error:code=Unknown desc=executor failed running [/bin/sh-c bundle config --local set path'vendor/bundle'&bundle install]:exit code:10

I got an error like .Also, I couldn't find any article that could solve this problem by googling this error.I don't think I can find Gemfile, but I don't know what to do anymore, so I decided to try another method.Also, this person had an error of ERROR: Service 'web' failed to build: Build failed, but for some reason he didn't.But as far as the files are concerned, they're probably doing the same thing as me.
·As I decided to give permission, the following command was not effective and the error statement remained the same.

#You may have done something meaningless.
senseiy@senseIY:~/Documents/rails_docker$pwd
/home/senseiy/Documents/rails_docker
senseiy@senseIY: ~/Documents/rails_docker $chmod777/home/senseiy/Documents/rails_docker

·As a beginner in programming, I think there are some parts where the perception is wrong.If you have any advice, please let me know.

Additional
You pointed out that there may be a discrepancy between local and container user permissions, so I asked you to look into it.
https://tech-blog.rakus.co.jp/entry/20200826/docker
We proceeded with this article as a reference.
First, rewrite the permissions on the first mounted volume.

 senseiy@senseIY:~/Documents/rails_docker $chmod777src
senseiy@senseIY:~/Documents/rails_docker$docker-compose run web rails new.--force--database=mysql
[+] Running 1/0
⠿ Container rails_docker-db-1 Running 0.0s
[+] Building 41.4s (7/9)
=>[internal] load build definition from Dockerfile 0.0s
=>=>transferring dockerfile:397B 0.0s
=>[internal] load.dockerignore 0.0s
=>=>transferring context—2B 0.0s
=>[internal] load metadata for docker.io/library/ruby:2.7 41.3s
=>[1/5] FROM docker.io/library/ruby:2.7 @sha256:490f9343c654ce108a1bd34b4896e5311350.0s
=>ERROR [internal] load build context 0.0s
=>=>transferring context—324B 0.0s
=>CACHED [2/5] RUN curl-sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add 0.0s
=>CACHED [3/5] WORKDIR/app 0.0s
------
>[internal] load build context:
------
failed to solve:rpc error:code=Unknown desc=error from sender:open/home/senseiy/Documents/rails_docker/src/db/mysql_data/#innodb_temp:permission denied

The error did not change specifically as shown in .
I tried to do the second one, but apparently I need to check the id in the container.In my case, there is an error in the initial setting (I haven't made a container yet, so I can't check the id by entering the docker-compose exec container name bash)."Also, the third one needs to be built in the middle, so I don't know what to do, so I got stuck again."If you have any advice, please let me know.

windows docker wsl-2

2022-09-30 10:26

2 Answers

chmod-R777src
Executed the above command (in my case - no R for some reason + all files were re-created)
has been able to resolve this issue.I hope it will be helpful for people like me who are stuck with errors.Thank you for your advice.


2022-09-30 10:26

If chmod-R777src doesn't work, run it as an administrator with sudo on your head.

$sudo chmod-R777src

This worked for me.


2022-09-30 10:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.