I'm trying to do:
FROM mysql:5.7
RUN rm -rf /var/lib/mysql
COPY ./db /var/lib/mysql
And I get the error :
rm: cannot remove '/var/lib/mysql': Device or resource busy
I don't really need to rm the folder, I just want to overwrite, but for some reason the dockerfile doesn't overwrite, the COPY instruction just seems to fail silently.
Not sure if there's caching going on or something but I use --no-cache, (this isn't the first time I built the image but files have changed).
How I can debug?
The mysql Dockerfile declares
VOLUME /var/lib/mysql
That directly leads to the error you're seeing. (At a low level Docker causes the volume to be mounted on that directory, as in the normal Linux mount command/function, so you can't delete the mount point.)
It also has the consequence that derived images can't make any changes in that directory tree, so your fundamental approach here won't work. If you already have a data tree that can work here, you can use the docker run -v option to mount it into a container
docker run -v $PWD/db:/var/lib/mysql mysql:5.7
If you just have a dump file, you can mount or copy it into /docker-entrypoint-initdb.d; this mechanism is described on the Docker Hub mysql image page (under "Initializing a fresh instance").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With