[Solved] How to start a chrooted directory as a docker container?


Finally I found a workaround.

Unfortunately, simply mounting “https://stackoverflow.com/” (either with the VOLUME command in the Dockerfile, or with giving the -v to docker run) doesn’t work – it can’t mount the root directory as a volume.

Furhtermore, VOLUME in the Dockerfile doesn’t seem to work at all.

The best (or, least worse) solution what can be done: mounting the sub-directories as different volumes. Around so:

docker run -d -h demobox --name demobox \
    -v /demobox/bin:/bin \
    -v /demobox/boot:/boot \
    -v /demobox/etc:/etc \
    -v /demobox/home:/home \
    -v /demobox/lib:/lib \
    -v /demobox/opt:/opt\
    -v /demobox/root:/root\
    -v /demobox/sbin:/sbin\
    -v /demobox/srv:/srv\
    -v /demobox/usr:/usr\
    -v /demobox/var:/var \
    demobox

Unfortunately, it also needs to have a fake image to run (it is “fake” because all of its relevant /* directories will be over-mounted by the docker daemon). You can use anything for that (I used the default image of the distribution).

Additional info: as entrypoint, we can also give /sbin/init to the container. In my tries, systemd wasn’t able to run in it, but upstart could (apt-get install upstart). Giving /sbin/init as ENTRYPOINT to the Dockerfile, then calling a telinit 3 after starting the container, we can essentially run a docker container as a virtual server.

solved How to start a chrooted directory as a docker container?