3

I was treing to set the project on my local machine as readonly for the docker container, like this:

docker run -d \
    -p 3000:3000 \
    -v $PWD:/app:ro \
    -v /app/node_modules \
    --name $1 \
    $(docker images | awk '{print $1}' | awk 'NR==2')

and I always get this error, only after I add the :ro bit as the optional parameter to the volume:

docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "/var/lib/docker/volumes/6ffd471c1bc7edc141b6569b4d8e16829c7c7ae1838e4cc924727b0a854de143/_data" to rootfs at "/app/node_modules" caused: mkdir /var/lib/docker/overlay2/60b790308084302171b1b339ee242862651d7d96ecf21fb9b0a8867326ca83b3/merged/app/node_modules: read-only file system: unknown.

I was following this tutorial and I am using docker-desktop and WSL2 on windows 11.

code_dude
  • 951
  • 2
  • 15
  • 28
  • 2
    You shouldn't need either of the `-v` options; the application code should generally be built into the image. The error means what it says, though, if you're replacing the image's `/app` with a read-only mounted directory then you can't mount `/app/node_modules` over it. – David Maze Apr 03 '22 at 16:59
  • 1
    Make sure `node_modules` exists in `$PWD` on your host. – BMitch Apr 03 '22 at 17:06
  • 1
    I added back the node_modules to my local host and removed the line with -v /node_modules and it works. – code_dude Apr 03 '22 at 17:21
  • 1
    I added back the node_modules to my local host and removed the line with -v /node_modules and it works. The argument the guy in the tutorial was making was something about the fact that we delete the node_modules from localhost because we are now developing on the docker container and the first bind volume -v $PWD:/app syncs our local folder with the /app on the container and thus also deleting the /node_modules. So he adds the second anonymouse volume -v /app/node_modules to sort of prevent the deletion of node_modules from the container. – code_dude Apr 03 '22 at 17:31

2 Answers2

1

Actually the :ro is causing issue here on building the container on first time you must have the node_modules folder locally after that you can delete it

0

In my case, i've solved this creating a container with --privileged parameter.

to do:

docker run --privileged -i --name master --hostname k8s-master -d ubuntu:20.04

now, its fine.

Marcelo Guedes
  • 1,419
  • 11
  • 10