First, a container choreography official documents
https://hub.docker.com/search?q=centos&type=image
FROM scratch
ADD centos-7-docker.tar.xz /
LABEL org.label-schema.schema-version="1.0" \
org.label-schema.name="CentOS Base Image" \
org.label-schema.vendor="CentOS" \
org.label-schema.license="GPLv2" \
org.label-schema.build-date="20181205"
CMD ["/bin/bash"]
The base image is created based scratch
Add a file centos-7-docker.tar.xz
Two containers need to meet a condition:
1, scratch Mirror
2, centos-7-docker.tar.xz a file
Explanation:
1, scratch the mirror did not exist, all the base image is the most primitive of a template image.
1.1 method for obtaining scratch mirror:
tar cf scratch.tar --files-from /dev/null
1.2 Import scratch mirror
docker import scratch.tar scratch
2, all files in centos-7-docker is actually the root system
2.1 The method of obtaining the centos-7-docker.tar.xz
2.1.1 Create a folder
mkdir /root/vroot
2.1.2 install the system commonly used software
yum -y install --installroot /root/vroot bash yum coreutils net-tools vim
2.1.3 Initialization root login environment
Copy / root / vroot / etc / skel / .. to all non-file to the beginning of the / root / vroot / root / below
cp -a vroot / etc / skel /.[!.]* vroot / root /
2.1.4 packed files to a virtual directory as the root package
tar -cJf centos-7-docker.tar.xz -C vroot ./
2.1.5 The official assigned file copy to Dockerfile
vim Dockerfile
2.1.6 create a mirror
docker build –t centos:latest
PS: two ways to create root landing environment.
The first:
Executed in the container
cp -a /etc/skel/.[!.]* /root/
Quit using the bash interpreter to re-visit
ctrl + p +q
docker ps -q # id get
docker exec -it id bash
The second:
On the physical machine:
chroot / root / vroot # Remount the root system
cp -a /etc/skel/.[!.]* /root/
The storage container is a mirror image
docker commit id mirror name: label name
docker commit 9c897e695486 docker.io/centos:latest
The Mirror said the tar file package, for use other docker host
docker save image name: Tag name -o filename .tar
docker save docker.io/centos -o centos.tar