p2pu / course-in-a-box

An open-source project for creating online courses, built by P2PU
https://course-in-a-box.p2pu.org/
MIT License
95 stars 492 forks source link

Docker? Running the course-in-a-box on my (local) box #146

Open Newman5 opened 9 months ago

Newman5 commented 9 months ago

Hey Gang! I know that this hasn't been updated recently. But here is my issue.

I'd like to create a tutorial (that could become a course) using the course-in-a-box. I figure I'd like to get it running locally.

When following the instructions for Local from the readme, I run this code:

nsl@LAPTOP: ~/ad-ipsum/p2pu-LMS-site$ docker run -i -t --rm -u 1000:1000 -p 4000:4000 -v `pwd`:/opt/app -v `pwd`/.bundler/:/opt/bundler -e BUNDLE_PATH=~/opt/bundler -w /opt/app ruby:2.7 bash -c "bundle install && bundle exec jekyll serve --watch -H 0.0.0.0"

I get this error: / is not writable. Bundler will use /tmp/bundler20231120-7-lprlp17' as your home directory temporarily. There was an error while trying to write to /home/nsl/opt/bundler/ruby/2.7.0`. It is likely that you need to grant write permissions for that path.

Any help would be great!

dirkcuys commented 9 months ago

Hi @Newman5

I think docker is creating the .bundler directory with root permissions, but the image itself runs as user 1000, which then doesn't have access to the directory.

sudo chown 1000:1000 .bundler/

should sort the problem out.

Newman5 commented 9 months ago

Hey Dirk! Thanks for the help. And, that chown command makes sense to me. But it didn't work. Here is a what I get: image

Any help would be appreciated. Thanks!

pvanheus commented 7 months ago

This is how I run it:

docker run -i -t --rm -u 1000:1000 \
    -p 4000:4000 -v $(pwd):/opt/app \
    -v $(pwd)/.bundler/:/opt/bundler \
    -e BUNDLE_PATH=/opt/bundler \
    -w /opt/app ruby:2.7 bash \
    -c "bundle install && bundle exec jekyll serve --watch -H 0.0.0.0"

This maps the bundler path to a local folder called .bundler and solves the ownership issue.

pvanheus commented 6 months ago

Apologies, there is an error in my example above... I think it only worked because on that machine I was user 1000. This works, without any chowns etc.


if [ ! -d .bundler ] ; then mkdir .bundler ; fi

docker run -i -t --rm -u $(id -u):$(id -g) \
    -p 4000:4000 -v $(pwd):/opt/app \
    -v $(pwd)/.bundler/:/opt/bundler \
    -e BUNDLE_PATH=/opt/bundler \
    -w /opt/app ruby:2.7 bash \
    -c "bundle install && bundle exec jekyll serve --watch -H 0.0.0.0"

@Newman5: on your command line you had BUNDLE_PATH=~/opt/bundler which will expand to $HOME/opt/bundler which in your case is /home/nsl/opt/bundler - thus the permission denied. You need to ensure that BUNDLE_PATH and the location that you map to $(pwd)/.bundler lines up.