I know it’s been a long time since I wrote anything on here. Frankly, I’ve been busy with work, and other personal projects. But it is worth noting that most of those projects were professionally oriented. Specifically, I’ve been teaching myself aspects of vSphere, Docker, and a host of other technologies. Late this summer I invested in a couple of nice Dell R710 servers which I’ve turned into a homelab wonderland.
With my new vSphere system, I now have a dedicated Docker box. I’ve been working with it for a couple of months now, running microservices like my Unifi controller, a CrashPlan container, even a couple of music managers like Headphones and Beets. I have an affinity for the team at linuxserver.io for their oft-updated and very well documented base images.
The problem is, I was playing around with it so much and making so many changes that I neglected to document the “docker run” commands correctly. I didn’t really document them at all. Every once in a while I’d like to perform a “docker pull” to retrieve the latest docker image and update my running containers, so the docker run commands along with the associated mapped ports and volumes would be extremely useful and time-saving.
I was looking for a way to reconstruct the original commands I used to build these containers. A number of possibilities presented themselves, but fortunately because I have a dedicated box (that is, not polluted with a lot of commands for unrelated services), I was able to recover exactly what the run commands were.
I simply made a copy of my bash history. It contained all of the exact commands are used to create the doctor containers from the very beginning. No guesswork, no time-consuming reconstruction of the commands. Just an exhaustive list of the last few hundred commands I’d performed with that user on that box.
I saw a bunch of online questions asking for basically the same thing, and instead of inferring the commands with “docker inspect” and parsing the results using Python, I thought I would offer an alternative.
Hopefully this proves useful to someone other than myself.
My docker host is running Ubuntu 16.04. I’m not sure if this is universal across all linux distros but it worked here:
history -w ~/history.txt
From there I just opened the text file and ran a search for all mentions of “docker run” and copied the last command string for each container.
Leave a Reply