In order to test the Docker images pruning with Openshift Origin I made the following test.
Environment:
- Two nodes, one master + infra and a workload node.
- Cluster version: Openshift Origin 3.6
First of all I have built a Docker image based on NodeJS within a large file. The file.out is of 50M and after compression it decreases little.
Structure of my NodeJS app
[root@origin-master nodeapp]# ls -lhas total 51M 0 drwxr-xr-x. 2 root root 106 May 27 16:41 . 0 drwx------. 6 vagrant vagrant 228 May 27 09:09 .. 4.0K -rw-r--r--. 1 root root 136 May 27 16:22 Dockerfile 4.0K -rw-r--r--. 1 root root 261 May 27 16:18 create_fake_images.sh 50M -rw-r--r--. 1 root root 50M May 27 16:18 file.out 4.0K -rw-r--r--. 1 root root 265 May 27 09:09 package.json 4.0K -rw-r--r--. 1 root root 539 May 27 15:19 server.js
The Dockerfile is very simple!
[root@origin-master nodeapp]# cat Dockerfile FROM node # Create app directory WORKDIR /usr/src/app COPY package*.json ./ RUN npm install COPY . . EXPOSE 8080 CMD [ "npm", "start" ]
The following script helped me to generate many images with additional and differents layers. Each iterations copy the 50M file inside the image.
for i in $(seq 1 1000) do echo "RUN echo $i" >> Dockerfile echo "COPY file.out ./$i.out" >> Dockerfile docker build -t docker-registry-default.origin.local/test/nodeapp:latest . docker push docker-registry-default.origin.local/test/nodeapp:latest done Let's see how the Docker registry folder increase size during create_fake_images.sh execution. 1a4c7633d886: Pushing [=======> ] 8.325 MB/52.43 MB e36035decad2: Pushing [=======> ] 7.768 MB/52.43 MB bb1e26b5f124: Pushing [=======> ] 7.768 MB/52.43 MB 13c3d2712668: Pushing [===========> ] 11.67 MB/52.43 MB dbc4876ab96c: Pushing [=======> ] 8.327 MB/52.43 MB [root@origin-master vagrant]# du -chs /data/origin/ 782M /data/origin/ 782M total [root@origin-master vagrant]# du -chs /data/origin/ 956M /data/origin/ 956M total [root@origin-master vagrant]# du -chs /data/origin/ 1.2G /data/origin/ 1.2G total
Describing image stream nodeapp we can see the latest images pushed to the registry
[root@origin-master nodeapp]# oc describe is Name: nodeapp Namespace: test Created: 2 hours ago Labels: <none> Annotations: <none> Docker Pull Spec: docker-registry.default.svc:5000/test/nodeapp Image Lookup: local=false Unique Images: 5 Tags: 1 latest pushed image * docker-registry.default.svc:5000/test/nodeapp@sha256:6f517f2bd667280587daebd57c456c723df4e97d72903100cad441821203e4ec 22 seconds ago docker-registry.default.svc:5000/test/nodeapp@sha256:421155780252a908de9c4968c65a508c65b12b259a6248278b73dd20edee20fb About a minute ago docker-registry.default.svc:5000/test/nodeapp@sha256:b26f1d2cac95a73632891a6cfec875baed0b1a4165c381e59e0ce4d1bfc403f9 About a minute ago docker-registry.default.svc:5000/test/nodeapp@sha256:6d6f63093aae64198fb1d7af2cd2a361cec991817c8e6944910cb84420a52c1b 20 minutes ago docker-registry.default.svc:5000/test/nodeapp@sha256:6e82ae61a154788ff70ff3ed69cf3a088845e0c7c2d1441de4123c213a0f0116 23 minutes ago
I changed the Dockerfile in order to have an image that does not import large file. So I have built and pushed the following Docker image
[root@origin-master nodeapp]# cat Dockerfile FROM node # Create app directory WORKDIR /usr/src/app COPY package*.json ./ RUN npm install COPY . . EXPOSE 8080 CMD [ "npm", "start" ]
Let’s start to prune
- Delete old deployments
[root@origin-master nodeapp]# oc adm prune deployments --orphans --keep-complete=1 --keep-failed=1 --keep-younger-than=1m Dry run enabled - no modifications will be made. Add --confirm to remove deployments NAMESPACE NAME test nodeapp2-23 test nodeapp2-22 test nodeapp2-21 test nodeapp2-20
- Prune the unused images and keep only one revision
[root@origin-master nodeapp]# oc adm prune images --keep-tag-revisions=1 --keep-younger-than=1m --confirm Deleting references from image streams to images ... STREAM IMAGE TAGS test/nodeapp sha256:6e82ae61a154788ff70ff3ed69cf3a088845e0c7c2d1441de4123c213a0f0116 latest test/nodeapp sha256:421155780252a908de9c4968c65a508c65b12b259a6248278b73dd20edee20fb latest test/nodeapp sha256:b26f1d2cac95a73632891a6cfec875baed0b1a4165c381e59e0ce4d1bfc403f9 latest Deleting registry repository layer links ... REPO LAYER LINK test/nodeapp sha256:3de138bf364bf3e2684c78468d07a0e2ca786ba08f83bd1b7e3373a1e0b407e5 test/nodeapp sha256:a75ed4d808fc563081de632debf91580a6dbe6d694971ca6888b5be4433f55cc test/nodeapp sha256:677e3bfb00ad311212b46be4ddb20f5b762765fef676c6d4a85e5dbcb943c4a4 test/nodeapp sha256:29510362ff8e174edf88563f6099141b9e82efd5cd48b14aeaa74fea532e6d43 test/nodeapp sha256:35dc109c74dfcab9f1f027ccc1404e7ef3f524d6efea226e3920959051819f2c test/nodeapp sha256:f3d40164b23c42356d717da92b91774402632a8df22cd5ddfb7926fc3a7292f6 test/nodeapp sha256:fe03b24c2c84648d09331dbd72a8065b8ed550be991155edc72ad1166f1ef666 test/nodeapp sha256:8eaf1a821a6b8a2e325cebce83311c5d3b33427140d84954f504ed59bab51109 test/nodeapp sha256:684c30e67a270d2115cb4be1c9712193bf0b4393ffa04b3c625e76fadd6bda12 test/nodeapp sha256:7d6ad63a8e94a938a95fa1e27106bbc7ecfa3680b3ff3a11c7bdb43ae610eb18 test/nodeapp sha256:e1614bf81372b99eb86c74ac9c023c01077061db81c4daeaf6683e27299e48cc test/nodeapp sha256:a92bff6ede96a89a94fe2ca794115e1c374312d05e895698e6b1638c3b647645 test/nodeapp sha256:2d9ccccdee639671c6cb24110e529b738535453a3ccdf68989ac31ea6894929d test/nodeapp sha256:1e920f3f2676bc50c60a95c9d8710cb91429ab07278616c02680b0f38af2d224 test/nodeapp sha256:90b58c4583c3de52b6f6762c83a02d42dd18747a2541bafb483a9cdbc5e55f8b test/nodeapp sha256:d041de45e8895ee77b4e6ba112959e361d888b5694910b44f54fb88f0ef3fb4f Deleting registry layer blobs ... BLOB sha256:3de138bf364bf3e2684c78468d07a0e2ca786ba08f83bd1b7e3373a1e0b407e5 sha256:a75ed4d808fc563081de632debf91580a6dbe6d694971ca6888b5be4433f55cc sha256:677e3bfb00ad311212b46be4ddb20f5b762765fef676c6d4a85e5dbcb943c4a4 sha256:29510362ff8e174edf88563f6099141b9e82efd5cd48b14aeaa74fea532e6d43 sha256:35dc109c74dfcab9f1f027ccc1404e7ef3f524d6efea226e3920959051819f2c sha256:f3d40164b23c42356d717da92b91774402632a8df22cd5ddfb7926fc3a7292f6 sha256:fe03b24c2c84648d09331dbd72a8065b8ed550be991155edc72ad1166f1ef666 sha256:8eaf1a821a6b8a2e325cebce83311c5d3b33427140d84954f504ed59bab51109 sha256:684c30e67a270d2115cb4be1c9712193bf0b4393ffa04b3c625e76fadd6bda12 sha256:7d6ad63a8e94a938a95fa1e27106bbc7ecfa3680b3ff3a11c7bdb43ae610eb18 sha256:e1614bf81372b99eb86c74ac9c023c01077061db81c4daeaf6683e27299e48cc sha256:a92bff6ede96a89a94fe2ca794115e1c374312d05e895698e6b1638c3b647645 sha256:2d9ccccdee639671c6cb24110e529b738535453a3ccdf68989ac31ea6894929d sha256:1e920f3f2676bc50c60a95c9d8710cb91429ab07278616c02680b0f38af2d224 sha256:90b58c4583c3de52b6f6762c83a02d42dd18747a2541bafb483a9cdbc5e55f8b sha256:d041de45e8895ee77b4e6ba112959e361d888b5694910b44f54fb88f0ef3fb4f Deleting registry repository manifest data ... REPO IMAGE test/nodeapp sha256:6e82ae61a154788ff70ff3ed69cf3a088845e0c7c2d1441de4123c213a0f0116 test/nodeapp sha256:421155780252a908de9c4968c65a508c65b12b259a6248278b73dd20edee20fb test/nodeapp sha256:b26f1d2cac95a73632891a6cfec875baed0b1a4165c381e59e0ce4d1bfc403f9 Deleting images from server ... IMAGE sha256:6e82ae61a154788ff70ff3ed69cf3a088845e0c7c2d1441de4123c213a0f0116 sha256:421155780252a908de9c4968c65a508c65b12b259a6248278b73dd20edee20fb sha256:b26f1d2cac95a73632891a6cfec875baed0b1a4165c381e59e0ce4d1bfc403f9
Check the size of registry folder
[root@origin-master nodeapp]# du -chs /data/origin/
608M /data/origin/
608M total
Ok from 1.6gb we went down to 608M !