1

When you are inside a docker container, is there anyway to obtain the "build history" (i.e. the original Dockerfile, or rather list of commands in the original Dockerfile that was used to build that container)?

The reason is that for tracking and version control purposes, it might be useful to indicate what/how the environment was configured when the process was run.

Thanks.

xnet
  • 511
  • 2
  • 7
  • 16
  • `docker inspect` will give you some basic info about the container, but not much. Generally if you are looking at image build by official providers, you may find their github repo and will be able to view their Dockerfile. Another tool to inspect docker image layers https://github.com/wagoodman/dive – Bala Aug 15 '19 at 22:50
  • You can’t find this information without giving the container unrestricted root-level access over the host. Consider using an `ARG` to pass in the information you need at build time instead. – David Maze Aug 16 '19 at 14:26

2 Answers2

0

You can do it with

docker history

command. But not inside the container. Container itself does not have Docker and container itself does not hold its own history. To run that command you need to be in the host and not in the container.

docker history documentation have a great explanation on how to use that command.

Ryukote
  • 767
  • 1
  • 10
  • 26
0

docker label is a good way to add additional metadata to your docker images.

Check this for more info.

You can get this data using docker inspect. But these commands can be run from outside the container, to run it from the inside you need to make use of docker remote api's as explained here in this answer.

You can also retrieve details of docker image using docker history through this remote api.

If you want just few details about images like version, etc. Then put those data as environment variable while building the image so that you can refer it later inside your running docker container.

mchawre
  • 10,744
  • 4
  • 35
  • 57