I use docker in my workflow as an application and environment manager. I switch between multiple physical computers a lot, and like to have things self contained within work spaces that I can move from one computer to another easily, normally using `git`. Here are a few tricks that I use to have the lightest touch on my local installation as possible.
If you want to install a specific set of software, you use a `Dockerfile` to create an `image`. If the `image` is already on docker hub, you don't need to write a Dockerfile.
Images are used to create containers, which are images that have started up. They could then be stopped and restarted if you need to, but they have long running state. Starting a container with `–rm` means that it cleans itself up after it ends, which is often what I want; go away after my attention wanders off.
Volumes – either docker managed or a directory exposed on the local file system – is a way for the storage that a container uses to be more durable. If you are running something "for real" you probably want to keep the data somewhere "outside" of the container so that if it goes away, or you update to a different image, you still have the data. I don't really use this feature.
Transient vs Semi-permanent vs Permanent
My usage of Docker can either be to poke at a piece of software, play around with it for a bit longer, or use it more seriously. One gets a transient container that deletes on shutdown, the next gets a name and sticks around, and the final one has long term storage outside of the container.
|`docker run -it –rm`
|`docker run -it –name something`
|`docker run -d –name something -v storage:storage`
Bash template for semi-permanent
In my projects I have a file called `LOCALSERVERS` that I run to make sure that the right containers are installed and started up when I start developing. The pattern is to create one if it doesn't exist, and then start it if it's not started. These containers are meant to stick around at least until I move on to other projects.
When you have a bunch of interelated services, using
docker-compose.yml is a great way to set things up. Especially if you
have volumes to attach and keep around. It's worth mentioning that
this is super useful, even if it doesn't fit into the 'one-liner'
Lets startup a postgres container that has postgis extensions installed:
Need a web interface to run SQL commands?
Explore your built images:
Easy temporary redis instance.