Source From Here
Question
Is it possible to generate a Dockerfile from an image? I want to know for two reasons:
How-To
To understand how a docker image was built, use the docker history command.
You can build a docker file from an image, but it will not contain everything you would want to fully understand how the image was generated. Reasonably what you can extract is the MAINTAINER, ENV, EXPOSE, VOLUME, WORKDIR, ENTRYPOINT, CMD, RUN, and ONBUILD parts of the dockerfile.
The following script should work for you:
I use this as part of a script to rebuild running containers as images:
https://github.com/docbill/docker-scripts/blob/master/docker-rebase
The Dockerfile is mainly useful if you want to be able to repackage an image.
The thing to keep in mind, is a docker image can actually just be the tar backup of a real or virtual machine. I have made several docker images this way. Even the build history shows me importing a huge tar file as the first step in creating the image...
Supplement
* Docker Doc - Dockerfile reference
* Docker Practice - Dockerfile
* Docker Practice - 從映像檔產生 Dockerfile
Question
Is it possible to generate a Dockerfile from an image? I want to know for two reasons:
How-To
To understand how a docker image was built, use the docker history command.
You can build a docker file from an image, but it will not contain everything you would want to fully understand how the image was generated. Reasonably what you can extract is the MAINTAINER, ENV, EXPOSE, VOLUME, WORKDIR, ENTRYPOINT, CMD, RUN, and ONBUILD parts of the dockerfile.
The following script should work for you:
- #!/bin/bash
- docker history --no-trunc "$1" | \
- sed -n -e 's,.*/bin/sh -c #(nop) \(MAINTAINER .*[^ ]\) *0 B,\1,p' | \
- head -1
- docker inspect --format='{{range $e := .Config.Env}}
- ENV {{$e}}
- {{end}}{{range $e,$v := .Config.ExposedPorts}}
- EXPOSE {{$e}}
- {{end}}{{range $e,$v := .Config.Volumes}}
- VOLUME {{$e}}
- {{end}}{{with .Config.User}}USER {{.}}{{end}}
- {{with .Config.WorkingDir}}WORKDIR {{.}}{{end}}
- {{with .Config.Entrypoint}}ENTRYPOINT {{json .}}{{end}}
- {{with .Config.Cmd}}CMD {{json .}}{{end}}
- {{with .Config.OnBuild}}ONBUILD {{json .}}{{end}}' "$1"
https://github.com/docbill/docker-scripts/blob/master/docker-rebase
The Dockerfile is mainly useful if you want to be able to repackage an image.
The thing to keep in mind, is a docker image can actually just be the tar backup of a real or virtual machine. I have made several docker images this way. Even the build history shows me importing a huge tar file as the first step in creating the image...
Supplement
* Docker Doc - Dockerfile reference
* Docker Practice - Dockerfile
* Docker Practice - 從映像檔產生 Dockerfile
This message was edited 10 times. Last update was at 22/06/2015 09:46:33
沒有留言:
張貼留言