The basic idea is to use the tool “debootstrap“, which can create a base Debian system by pulling all needed files into a given directory. Then create a tar file upon the directory and import that tar(image) file into Docker. After that the image can be used as any other ones in Docker. Debian is the best Linux distro!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# The first "wily" is the name of the target directory, the # second wily is the mirror name(the alias of Ubuntu 15.10). # After the execution a "wily" directory will be created. sudo debootstrap wily wily
# The following command will create a tar stream(the image) # and put the image into Docker. sudo tar -C wily -c . | docker import - wily
# Then run the following command to check. docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE wily latest b1e26f8656c7 23 minutes ago 222.1 MB java 7 beabd1eef902 6 days ago 587.3 MB java latest beabd1eef902 6 days ago 587.3 MB ubuntu latest 07f8e8c5e660 3 weeks ago 188.3 MB mysql latest 56f320bd6adc 4 weeks ago 282.9 MB
How to save/load images
One can use Docker save/load commands to persist an image into tar file and vice versa. For an example:
docker save -o wily_latest.tar wily:latest docker load -i /media/sf_exchange/docker/ubuntu_latest.tar
Here is an article about the difference between Docker “save” and “export”.
Some other useful commands
1 2 3 4 5 6 7 8 9 10 11
# 1. Start a new container instance. docker run -it ubuntu /bin/bash
# 2. List all container instances including the stopped ones. docker ps -a
# 3. Start a stopped container instance. docker start eb344a5ba6b1 # The container instance ID.
# 4. Attach to a running container instance. docker attach eb344a5ba6b1