1. Create a folder
mkdir mynginx cd mynginx touch Dockerfile
[@ VM_0_10_centos the root mynginx] CAT # Dockerfile the FROM Nginx: 1.17 # first mirrored RUN echo echo '! <h1> Hello, zjy </ h1>'> /usr/share/nginx/html/index.html
1-1, if not the first layer mirror, mirror blank scratch
FROM scratch ...
1-2, dockerfile limited the maximum number of layers of the mirror
Union FS is largest number of layers is limited, ⽐ as AUFS, once the most zoomed shall not exceed the 42-story, now is not more than 127 layers.
Dockerfile 正确的写法应该是这样: FROM debian:jessie RUN buildDeps='gcc libc6-dev make' \ && apt-get update \ && apt-get install -y $buildDeps \ && wget -O redis.tar.gz "http://download.redis.io/releases/redis-3.2.5.tar.gz" \ && mkdir -p /usr/src/redis \ && tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \ && make -C /usr/src/redis \ && make -C /usr/src/redis install \ Dockerfile 定制镜像 27 && rm -rf /var/lib/apt/lists/* \ && rm redis.tar.gz \ && rm -r /usr/src/redis \ && apt-get purge -y --auto-remove $buildDeps #而不是这样怎写的 FROM debian:jessie RUN apt-get update RUN apt-get install -y gcc libc6-dev make RUN wget -O redis.tar.gz "http://download.redis.io/releases/redis-3.2.5.tar.gz" RUN mkdir -p /usr/src/redis RUN tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 RUN make -C /usr/src/redis RUN make -C /usr/src/redis install
2. mirrored
docker build -t nginx:v3 .
3, dockerfile will build context
If you pay attention, you'll see docker build a final order.. Represents the current directory, Dockerfile in the current directory.
COCP instruction when executed on the package will mirror the current directory, if placed in the root directory dockerfile, a mirror may be packaged tens G, so it embarrassing
./Package.json COPY / App / # ./package.jso Catalog # or copy all packed into dockerfile located in all, this was true
Dockerfile will be placed under an empty directory, or the project root directory. In fact Dockerfile the names are not required must be Dockerfile, and does not require to be located up and down the directory -f ../Dockerfile.php parameter specifies a file as Dockerfile
4, mirroring the migration
Docker docker load and also provides a docker save command to save the image as a tar file, and then transferred to another position, and then loaded in. This is the practice in the absence of Docker Registry, is now not recommended, mirroring the migration should be directed to the Docker Registry, either directly or using Docker Hub within the private network Registry can be.
[root@VM_0_10_centos mynginx]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx v3 1af39fd25fb3 29 minutes ago 126MB nginx v2 7d3e771ab88b 5 hours ago 126MB nginx 1.17 f949e7d76d63 38 hours ago 126MB ubuntu 16.04 657d80a6401d 7 days ago 121MB [root@VM_0_10_centos mynginx]# docker save nginx:v3|gzip > nginx_v3.tar.gz [root@VM_0_10_centos mynginx]# ls Dockerfile nginx_v3.tar.gz [root@VM_0_10_centos mynginx]# du -sh nginx_v3.tar.gz 47M nginx_v3.tar.gz [root@VM_0_10_centos mynginx]# docker rmi 1af39fd25fb3 Untagged: nginx:v3 Deleted: sha256:1af39fd25fb3616ea2efd24d00e0f77309c6a8c6af4ab527678a6adea1250991 Deleted: sha256:d2549ea8e90863f679a50fd3378bd9c06fd766107565f53435134d40470c7799 [root@VM_0_10_centos mynginx]# docker load -i nginx_v3.tar.gz 44d9a80fe7fc: Loading layer [==================================================>] 4.096kB/4.096kB Loaded image: nginx:v3 [root@VM_0_10_centos mynginx]# docker im image images import [root@VM_0_10_centos mynginx]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx v3 1af39fd25fb3 30 minutes ago 126MB nginx v2 7d3e771ab88b 5 hours ago 126MB nginx 1.17 f949e7d76d63 38 hours ago 126MB ubuntu 16.04 657d80a6401d 7 days ago 121MB