If you have not heard of Docker yet, then this will help you understand what it is and how to use Docker effectively.
What is Docker?
Here is the definition of the Docker site:
Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.
Learn more here: https://www.docker.com/what-docker
Docker provides an easy setup package to get you started fast. Just follow the following instructions depending on you operating system.
Starting a docker container
Once you have completed the setup of Docker it is relatively straight forward to start your first container. Open a command line console and type the following command:
docker run hello-world
Docker will go to their online repository and pull down the specified container image "hello-world" to your machine. Docker will then start the container as well.
You should see the following output in your command line console
Figure 1 - Docker Pull Console Output
You can explore the public registry available from Docker here:
Once you have created an account you can setup your own private registry at Docker.
Important Docker commands
There are various Docker commands that you can use, but I found the below commands the most used commands in daily development practice.
# Pulls an image from the registry to your local machine. docker pull hello-world # Creates and starts a container in one operation. docker run hello-world # Lists containers that are running. docker ps -a # Show list of images on your machine. docker images # Delete a particular image. docker rmi 2873hh433
Here are relevant commands but can be dangerous to use.
# Delete every Docker image docker rmi $(docker images -q) # Delete every Docker containers docker rm $(docker ps -a -q)
Here is a very helpful cheat sheet on Docker commands:
What is a Dockerfile? Well, it is a configuration file to setup a custom container. Here is an example of setting up a Nodejs container:
FROM risingstack/alpine:3.3-v5.5.0-1.1.3 COPY package.json package.json RUN npm install COPY . . EXPOSE 1337 ENTRYPOINT ["npm","start"]
Execute the following commands to build the container based off your Dockerfile.
docker build -t test/test:latest . docker run --name nodetest -p 127.0.0.1:80:8080 -i test/test:latest /bin/sh
Read more about details on the Docker configuration file here:
Latest Docker for Windows and Mac OS X release
Recently Docker has released a new Docker for Windows and Docker for Mac OS X beta to make it easier to work with Docker on Windows and Mac OS X. The Docker for Windows tool now works with HyperV so you don't need Virtualbox anymore which was required with Docker Toolbox.
Here are a couple screenshots from a Windows machine:
Once Docker is installed, you will see a new Docker icon in the bottom right of your desktop toolbar.
Figure 2 - Docker icon on desktop toolbar
You can right-click on the icon to get access to various options for Docker.
After Docker has started up and is initialized, you will see this screen.
Figure 3 - Docker up and running successfully
I hope this article helps you and gives you the confidence to get started with Docker. I challenge you to try and setup a basic three-tier application (Web Application Layer, Database Service Layer, and Cache Service Layer) with Docker.
If you have any problem, there is a big Docker community to help you. You can also contact me via Twitter. Let me know what you like or dislike about using Docker in your development flow.