Cooking with Docker: useful tips for beginners
Last week I wrote a quick introduction to getting started with Docker -- a modern replacement for traditional application virtualisation. I covered creating a Docker testing environment and using it to quickly start an instance of R's web application framework called Shiny.
I also attended the Sydney Docker March meetup at Atlassian, hearing about the experiences and challenges with using Docker in production.
Since then, I've compiled this list of the various helpful bits and pieces I've picked up from working with Docker:
Skip 'sudo' for commands
You may have noticed in my last post that the 'sudo' authorisation was prepended to each Docker command. To skip this, add your account to the 'docker' user group. Create the group if it does not exist, add your account (replace 'deliciousdata' with your own) and restart Docker:
sudo groupadd docker sudo gpasswd -a deliciousdata docker sudo service docker.io restart
You will need to log out for the changes to take effect.
See running containers
As you try out various different packages on the Docker registry, you'll be starting many containers. Track what's running easily with ps:
docker ps
The -a flag shows all containers, not just those that are running:
docker ps -a
Customise container names
You can reference your containers in Docker commands by specifying a custom name. This way, instead of refering to an ID such as '191baf3d0d19' or trying to remmeber an auto-generated name such as 'cranky_hawking' or 'trusting_brown') when starting, stopping or attaching a container, you can use 'shiny', for example.
docker run --name shiny rocker/shiny
Detach a container without it stopping
When attached to a container, you can easily detach it with CTRL-C, however this will also stop the container. Running the container with the -t flag will allow CTRL-C to detatch it without closing:
docker run --name shiny -t rocker/shiny
Run a container unattached
You can run a Docker container without attaching it's stdout using the -d flag:
docker run --name shiny -t -d rocker/shiny
Link two containers
To allow a Docker container to see another, the --link command can be used (this command runs a Shiny container linked to an existing Redis container -- Redis is a NoSQL key-value server. You can use Redis with Shiny through the rredis package):
docker run --name shiny --link redis:redis rocker/shiny
Map a container directory to the host filesystem
The -v command allows you to specify a directory in the container to map to the host filesystem as /host/os/path/:/path/in/container/. This was particularly useful for exposing the Shiny server directory so to modify the served application.
docker run --name shiny -p 3838:3838 -v /srv/shiny-server/:/srv/shiny-server/ rocker/shiny
That's all for now.
This week is Docker will be two years old, and Optiver is hosting a birthday party "open-source-a-thon" to help non-programmers, beginners and Docker-aficionados contribute to the project. Happy Birthday Docker!













