Flimm
Flimm

Reputation: 151278

How can I make my own base image for Docker?

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.


Edit: official documentation on creating a base image

Upvotes: 110

Views: 97160

Answers (5)

Larry Cai
Larry Cai

Reputation: 60143

(credit to fatherlinux) Get information from https://developers.redhat.com/blog/2014/05/15/practical-introduction-to-docker-containers/ , which explains better

  1. Create the tar files for your file system, simply could be

    tar --numeric-owner --exclude=/proc --exclude=/sys -cvf centos6-base.tar /
    
  2. Transfer the tar file to other docker system if not installed locally and import it

    cat centos6-base.tar | docker import - centos6-base
    
  3. 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.

Upvotes: 23

Mike
Mike

Reputation: 298

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

Upvotes: 15

Jessie Frazelle
Jessie Frazelle

Reputation: 635

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.

Upvotes: 6

Flimm
Flimm

Reputation: 151278

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

Upvotes: 33

creack
creack

Reputation: 121792

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

Upvotes: 37

Related Questions