First let me apologise for this very text heavy post.
In my quest to get on top of this “Docker Thing” I have been using BSDPy in a Docker container and have found it fantastically easy to use and deal with, especially at scale. I can bring a Linux server up and have it acting as a NetBoot server in just a few minutes. If you haven’t checked out BSDPy yet then have a look at it here
The one thing that was slightly annoying to me though was that I had to share a folder from my linux host to to the BSDPy Docker container, this was the
/nbi folder which contained my NBI’s
For example i would normally run:
docker run -d -p 0.0.0.0:69:69/udp -p 0.0.0.0:67:67/udp -p 0.0.0.0:80:80 -e DOCKER_BSDPY_IP=172.16.16.16 -v /storage/nbi:/nbi:rw --name bsdpy macadmins/bsdpy
The section there “
-v /storage/nbi:/nbi:rw ” what that is doing is, its taking the folder that exists on the linux host at
/storage/nbi and mounting that into our bsdpy container at
So in order to get NBI’s into the bsdpy container for it to serve to our clients, we have to upload them somehow to
/storage/nbi on our linux host – this could be done via
scp, rsync or something like that. A little bit painful.
I thought why don’t I put my NBI’s into a data only container, then I can have the BSDPy Docker container access the data only container instead. This makes deploying my NBI’s a lot easier as well, instead of having to scp them or rsync or some other method to get them onto the file system, I can instead just have docker pull down the container that houses the NBI at the same time as it pulls down the BSDPy container
Now instead of telling docker to map
/storage/nbi from the host to the docker container, we tell docker to use the exposed volume on the data only container and mount that into
/nbi instead with a command like this
docker run -d -p 0.0.0.0:69:69/udp -p 0.0.0.0:67:67/udp -p 0.0.0.0:80:80 -e DOCKER_BSDPY_IP=172.16.16.16 --volumes-from nbi-data-only --name bsdpy macadmins/bsdpy
So how do we go about creating this Data Only docker container and how do we get our NBi’s into it?
Well its actually really simple.
First start on a linux host that has docker installed, log in as root and create a directory which will be your working directory i like to use somewhere like
Move into this directory and create a
A Dockerfile is kind of like a script that Docker uses to generate an image.
The first thing we want to put in this docker file is some info about our container, we can simply comment this out so Docker ignores it but if we look at it later we know whats going on.
# Docker Data-Only Container to hold # NetBoot NBI images, for use with BSDPy Docker containers # This allows for easy portability and maintenance # Version 0.1 # Author Calum Hunter # Data 11/11/14
Now we add our first command
This will tell docker to use an existing image (busybox) as a base
We also add
MAINTAINER Calum Hunter (email@example.com) This is just to let docker know who create the image
Now we can put some RUN commands in the docker file so that the build process runs these commands at build time
RUN mkdir /nbi
RUN chmod -R 755 /nbi
These commands create the directory we need in the new image.
Now we need to get our NBI we want to add into our data container into our working directory. We need to have our .nbi folder in the same directory as our Docker file. So do whatever you would normally do in order to get your NBI into this directory whether it be SCP, rsync, fileshare whatever.
Now in our Dockerfile we want to run another command that is going to copy our NBI into our data only container
ADD Auto_NBI_14A389.nbi /nbi/Auto_NBI_14A389.nbi
RUN chmod -R 755 /nbi
So now we have copied the nbi into our data container, we need to tell the container what volume we want to expose and make available to other containers. We do this by using the
Last is the
CMD command which tells docker what command to run when the container is started, this can just be a basic shell command such as
So now we should have a completed Dockerfile that looks like this
# Docker Data-Only Container to hold # NetBoot NBI images, for use with BSDPy Docker containers # This allows for easy portability and maintenance # Version 0.1 # Author Calum Hunter # Data 11/11/14 FROM busybox MAINTAINER Calum Hunter (firstname.lastname@example.org) RUN mkdir /nbi RUN chmod -R 755 /nbi ADD Auto_NBI_14A389.nbi /nbi/Auto_NBI_14A389.nbi RUN chmod -R 755 /nbi VOLUME /nbi CMD ["/bin/sh"]
Now its time to build it!
First think about where you’re going to store this nbi, I’ll assume that you’re just going to upload it to the docker hub. The reason for this is that when you push your image up to a repository such as the docker hub it will use this naming convention to work out where to save it.
So my build command looks like this
build -t hunty1/nbi-data-only .
So essentially its
This will build the container locally on your machine, once its completed you should be able to see the new image listed when you run
If you wanted to upload this image to the docker hub you would simply run
docker push hunty1/nbi-data-only
username/container-name of course to match your needs
So now all we would have to do on a brand new host is install docker and then run
docker run -d -p 0.0.0.0:69:69/udp -p 0.0.0.0:67:67/udp -p 0.0.0.0:80:80 -e DOCKER_BSDPY_IP=172.16.16.16 --volumes-from hunty1/nbi-data-only --name bsdpy macadmins/bsdpy
Now that is pretty cool.
Next on the list – setting up your own private registry to store your docker images….