I am curious about what base image my image is based upon. There seems no easy and straightforward way to do that. So for example I want to know the base image of open
For pulled images, I don't think there is a way to find the base image without seeing the actual dockerfile because when you pull an image, image manifest is downloaded only for the leaf layer. So the image id of the non-leaf layers in marked as <missing>
in docker history
and you wouldn't know the repo tags of those layers.
If the image is built on your machine but if you don't have the dockerfile, you can find the base image as follows:
docker history
prints the image ids of the layers. Then you can get the repo tags using docker inspect
. The base image used will usually be the last layer in the output of docker history
.
eg:
$ docker history t:1
IMAGE CREATED CREATED BY SIZE COMMENT
10b4cce00fb8 3 days ago /bin/sh -c #(nop) CMD ["flask" "run"] 0B
824987ef6cab 3 days ago /bin/sh -c #(nop) COPY dir:1973b65388e92428e… 406B
d4b6f433a5df 3 days ago /bin/sh -c pip install -r requirements.txt 4.98MB
8827b3f01d00 3 days ago /bin/sh -c #(nop) COPY file:98271fcaff00c6ef… 0B
65b8c98138e6 2 weeks ago /bin/sh -c apk add --no-cache gcc musl-dev l… 113MB
01589531f46d 2 weeks ago /bin/sh -c #(nop) ENV FLASK_RUN_HOST=0.0.0.0 0B
6c4640b8027a 2 weeks ago /bin/sh -c #(nop) ENV FLASK_APP=app.py 0B
b4c8fc7f03d6 2 weeks ago /bin/sh -c #(nop) WORKDIR /code 0B
16a54299f91e 2 weeks ago /bin/sh -c #(nop) CMD ["python3"] 0B
$ docker inspect 16a54299f91e
[
{
"Id": "sha256:16a54299f91ef62cf19d7329645365fff3b7a3bff4dfcd8d62f46d0c9845b9c6",
"RepoTags": [
"python:3.7-alpine" ---> Base image used in FROM instruction.
Following the output of docker history
in reverse order, you can approximately recreate the Dockerfile.
You can also use the chenzj/dfimage
image which runs a script which does the same to reconstruct the dockerfile.
alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm chenzj/dfimage"
$ dfimage 10b4cce00fb8
FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN /bin/sh -c apk add --no-cache gcc musl-dev linux-headers
COPY file:98271fcaff00c6efb6e58bd09ca726c29947e0cfe7031a8d98878cc01561fbbf in requirements.txt
RUN /bin/sh -c pip install -r requirements.txt
COPY dir:1973b65388e92428e30f835a67ebc8c7b00ec648fbea0717af6d501af162186b in .
CMD ["flask" "run"]
bash-3.2$