I always wanted to have the functionality of re-creating docker containers based on new images, coming from, for example, CI builds. Docker does not provide this functionality out of the box, and it does involve some operations, like transferring environment variables, copying links, etc.
It's like using the ES7 spread operator: const newContainer = {...oldContainer}; (At least, the mental model is.)
Luckily, @lanrat wrote a small Gist doing exactly this: https://gist.github.com/lanrat/8a8b385959627a7b29f1. This is the origin of this small application. docker-machine is fine, and with docker-recreate, CI builds (or, simply, different image versions) are easily applied.
You'll need Go and dep. To install, check out the code via go get github.com/fallafeljan/docker-recreate. Install via make. Then, run it:
docker-recreate [-p] [-d] id [tag]
-pPull the image from the repository.-dDelete the then-old container when the new one is running.idContainer ID of the container to-be-recreated.tagA different tag than the currently selected may be specified. (staging, for example.)
You may provide credentials for private repositories by specifying them in ~/.recreate.json:
{
"registries": [
{
"host": "registry.acme.corp",
"user": "dane",
"password": "joe",
}
]
}