UPDATE: Looks like this post is moot as of today 3/24/2016 due to Docker for Mac and Docker for Windows betas coming out
While interviewing for a new gig I was asked to use memcached and they had suggested standing up a docker instance. I have been using docker pretty regularly now after learning much from my previous co-workers and practical usage.
So, on OSX you can install the docker-machine and docker brew formulas with homebrew. (If you are not using homebrew and cask to manage your installations on OSX you are missing out). I use VirtualBox as my VM hosting tool.
If you haven’t installed (tapped) cask for application (non-CLI, GUI apps) installations, you should do it now:
| |
Now install the items:
| |
On Linux you don’t need docker-machine as you can just use docker directly, but on OSX you need the set up a Linux host through a VM tool like Virtualbox. You need to setup your docker-machine with the following command:
| |
This creates the docker host on virtualbox and names it default. So when you run docker-machine ls you will see something like the following:
| |
I created a Dockerfile to create the docker image with the following content:
| |
This Dockerfile will do the following:
- create a new image based on the latest Ubuntu docker image on DockerHub.
- set the maintainer to myself
- update the instance
- install memcached
- cleanup the update/install
- expose port 11211 from the instance
- run the arguments against the entry point (memcached)
- set user to daemon
- set entry point to be memcached
After the docker host is create I then built the image with the following command:
| |
-t lets you set a tag on the image so you can use that instead of the unique ID when creating the instance.
To see the new image you run the following:
| |
and you’ll see something like:
| |
Note: To delete the image you would use the docker rmi memcached_img command.
I then created the docker instace based on the new docker image with the following command:
| |
You should receive the sha of your new container instance. To see the instance information run docker ps. The result is
| |
As you can see this shows the mapping from the host port of 45001 to the container instance port of 11211 (defaul for memcached).
Note: You may need to add the -a argument to the docker ps command to see all container instances (including the ones not currently running).