How can I make my own base image for Docker?
DockerDocker Problem Overview
According to the Docker documentation, to build your own image, you must always specify a base image using the FROM
instruction.
Obviously, there are lots of images to choose from in the Docker index, but what if I wanted to build my own? Is that possible?
The image base
is built off Ubuntu if I understand correctly, and I want to experiment with a Debian image. Plus, I want to really understand how Docker works, and the base
image is still a blackbox for me.
Docker Solutions
Solution 1 - Docker
You can take a look at how the base images are created and go from there.
You can find them here: https://github.com/dotcloud/docker/tree/master/contrib. There is mkimage-busybox.sh, mkimage-unittest.sh, mkimage-debian.sh
Solution 2 - Docker
Quoting Solomon Hykes:
> You can easily create a new container from any tarball with "docker import". For example: > > debootstrap raring ./rootfs > tar -C ./rootfs -c . | docker import - flimm/mybase
Solution 3 - Docker
(credit to fatherlinux) Get information from https://developers.redhat.com/blog/2014/05/15/practical-introduction-to-docker-containers/ , which explains better
-
Create the tar files for your file system, simply could be
tar --numeric-owner --exclude=/proc --exclude=/sys -cvf centos6-base.tar /
-
Transfer the tar file to other docker system if not installed locally and
import
itcat centos6-base.tar | docker import - centos6-base
-
Now you can verify by running it.
docker run -i -t centos6-base cat /etc/redhat-release
The scripts from dotcloud combine first two steps together which make me confused and looks complicated in the beginning.
The docker official guideline using debootstrap
also tries to make clean file system.
You can judge by yourself how to do step 1.
Solution 4 - Docker
To start building your own image from scratch, you can use the scratch
image.
> Using the scratch “image” signals to the build process that you want the next command in the Dockerfile to be the first filesystem layer in your image.
FROM scratch
ADD hello /
CMD ["/hello"]
http://docs.docker.com/engine/articles/baseimages/#creating-a-simple-base-image-using-scratch
Solution 5 - Docker
If you want to make your own base image I would first take a look at
Official Images, specifically stackbrew
inside that repo.
Otherwise there are some great references for minimal OS images in the docker repo itself.
For example here is a script for making a minimal arch image and there are more here.