The problem I thought I initially had was because of how I had programmed the script run by the docker container to create the chroot.
It is possible to create a 32-bit chroot in a docker container. I had to run a privileged container, otherwise I could not mount required dirs/file systems (Ex:
/proc) to the chroot (And I would receive errors).`
I had to modify the steps I used slightly:
- The docker command I used was:
docker run -t --rm --name "chrootTest" -v $(pwd):/root/<CHROOT_SCRIPT_DIR> --privileged --workdir /root/<CHROOT_SCRIPT_DIR> <IMAGE>:<TAG> ./build-chroot.sh <CHROOT_DIR_LOCATION>
- I do not have to mount
/sys for the chroot modifications I am doing. (The modifications consist of removing directories/files/symlinks and
apt-get install-ing some dependencies. I only needed to mount
/proc for these actions, but if you are doing something different you may need to mount the other directories.)
- The script untars the archive into
<CHROOT_DIR_LOCATION> and copies the resolve.conf from the host to the untarred file system, while also making any required dirs for mounting.
- Then I have a heredoc that goes into the chroot and does required setup
chroot "$CHROOT_DIR_LOCATION" /bin/bash <<'EOF' ... EOF
- After setup I tar up the chroot files system, and remove the workdir
<CHROOT_DIR_LOCATION> and the script ends and the docker container is removed.
Because of the volume mount, the tar archive with the newly created chroot still exists on the host running the docker command.