Nano template
This is a template for building your own Docker nano products using the provided Buildroot container. You can also reuse this template later to update your products after this template has received updates by merging in any changes.
Usage
Using the template is as simple as cloning this source and inserting your product's name into a few files, replacing the <product> placeholders, as outlined in the following steps.
- Clone (
git clone --recursive
) this repository (forking is for updating the template itself). - Update
settings
with the name of your product.NANO_IMAGE
– The Buildroot image tag as listed indocker images
.NANO_CONTAINER
– The Buildroot container name as listed indocker ps
.
- Follow the building instructions from the Buildroot repository making sure to pull your config and rootfs afterwards.
- Add your name and email address to
Dockerfile
and uncomment theCOPY
line. Rebuild the image to ensure it still works. - Add your name and email address to
product/Dockerfile
and any other build steps required to configure your product. - Build your product with
docker build -t nano/<product> product
. - Test it with
docker run -it --rm nano/<product>
or similar. - Update
.travis.yml
test to check for the presence of your binary in the rootfs. - Replace this readme with the distributed one (
mv README.md.dist README.md
). - Update
README.md
andproduct/README.md
so others know how to use your product. - Tell us! Get in touch with a member of the Docker nano team so we can add your product to the registry for others to use.
Following is information for advanced modifications that may be required.
Patching Buildroot
If you wish to make changes to Buildroot you can either copy files into place or create a patch by following the steps below. Prefer copying if you're adding new files and patching if you're changing existing files, so it's clear which changes have been made.
-
Copy the file –
cp -bf file{,}
. -
Edit the file –
editor file
. -
Create the patch –
diff -u file{~,} > ~/buildroot/patches/my.patch
. Ensure the patch name accurately describes the purpose of the patch. -
Edit the patch header. A typical patch header may look like the following.
--- file~ 1970-01-01 00:00:00.123456789 +0000 +++ file 1970-01-01 00:00:00.123456789 +0000 @@ -1,0 +1,1 @@ +foo
Nano patches are applied in the context of the Buildroot source directory (
~/buildroot
) so if you are patchingfile
of thefoobar
package then the relative path should be inserted into the patch header. The first line and time information should be removed. After editing the modified patch file may look similar to the following.+++ package/foobar/file @@ -1,0 +1,1 @@ +foo
-
Copy patches back to the host –
./nano pull patches
. -
Uncomment the patching directives in the
Dockerfile
template. -
Rebuild your container and ensure the patches are applied correctly.
Modifying the rootfs
If you wish to add to or overwrite files in the rootfs image simply add those files to in/rootfs_overlay
and uncomment
COPY in/rootfs_overlay /root/buildroot/rootfs_overlay
in your Dockerfile
. Buildroot is already configured to pick
up files in this directory and merge them into the rootfs using the directory structure you provide in the overlay
directory.
To remove files modify the post_build.sh
script. The post-build script is configured to run in the context of the
rootfs directory. New instructions should be appended to the existing script by modifying the Dockerfile
, for
example, RUN echo rm -r var/run >> buildroot/post_build.sh
will remove /var/run
from the rootfs. Don't forget to
update .travis.bash
with the same commands to modify post_build.sh
.
For more information see customizing the generated target filesystem.