This guide is all about getting up and running with Docker.
The guide is summarized as follows:
- Docker Playground
- Installation
- Docker Playground
- Hello Docker
- Get Help
- Run First Container
- Learning Resources
- Summary
If you desire to play with Docker without having to install it, please have a look at 'Play With Docker (PWD)'.
According to the official PWD documentation, PWD can be summarized as follows:
PWD is a Docker playground which allows users to run Docker commands in a matter of seconds. It gives the experience of having a free Alpine Linux Virtual Machine in browser, where you can build and run Docker containers and even create clusters in Docker Swarm Mode.
Therefore, one is able to play with Docker without having to set anything up. Each session is limited to 4 hours, therefore it should be noted that anything you do in this sandbox environment will only be temporary.
I am not going to detail the Docker installation process. Instead, please see the official Docker installation documentation for detailed instructions on installing Docker on various platforms.
For convenience, I provide links to some of the common installation guides as follows:
After setup is complete, we can run the following commands to verify that Docker is running correctly.
docker -v
Provides a short description of Docker version
docker version
Provides full description of Docker version.
docker info
Display system wide information relating to Docker.
To get all Docker information as a JSON document, type the following command:
docker info --format '{{ json . }}'
As can be seen by image above, the result of running the command is a JSON document. The problem is that it's not easily readable. Therefore, to solve this issue one can use the jq command-line JSON processor. To install jq, please see the official installation documention. Linux, Windows, and OSX operating systems are supported.
Once jq is installed, issue the following command:
docker info --format '{{ json . }}' | jq
If one wanted to view a specific fragment of the JSON, then one would issue a command similar to the following:
docker info --format '{{ json .Plugins.Network }}' | jq
Docker does not support the concept of an 'alias' in the same way 'Git' does for example. However, using a Linux based OS, one can easily create 'aliases' for Docker commands by setting up aliases in the .bashrc
or .bash_aliases
file.
If one wanted to extract specific information (like server and registry information) relating to Docker, one could combine the 'docker info' command with the Linux 'grep' command as follows:
docker info | grep -iE 'server version|username|registry'
But having to combine docker and grep commands can become tedious. Therefore, if you're running a Linux based operating system, or if you're running Windows Subsystem for Linux (WSL) then you could setup your own docker command aliases as follows:
-
Firstly, create/update
.bash-aliases
file:cd ~ echo "alias docker-summary='docker info | grep -iE \"containers|running|paused|stopped|images|swarm|server version|username|registry\"'" >> ~/.bash_aliases source ~/.bash_aliases
The above command will create a new alias called 'docker-summary' in the
.bash_aliases
file. The output from 'docker info' is piped into a grep command. The 'grep -iE' part of the grep command indicates a case insensitive search using extended regular expression. -
Secondly, open
.bashrc
file and ensure the following code is present or uncommented:if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi
If you had to make changes to your
.bashrc
file then you will need to run the following command:source ~/.bashrc
-
For the last step we can run our docker alias command called
docker-summary
as follows:docker-summary
To get a list of available Docker commands and their descriptions, use the following command:
docker --help
To get help for specific Docker commands, type the command followed by the help switch as illustrated below:
docker image --help
Just like programming has the concept of a 'hello world' program, so too does Docker in the form of it's 'hello-world' image. To run your first Docker container, type the following command:
docker run hello-world
Looking at the image above, one will notice that in order to run the container, Docker first had to retrieve the 'hello-world' image from the official Docker Registry. Once downloaded, a container could be started. Please take note of the steps that Docker had to take in order to display the 'hello world' message.
-
Docker
-
Online Courses
-
Books
In this guide we covered the essential steps required to getting started with Docker. The 'Play With Docker' website provides a Docker sandbox environment that allows one to learn Docker without having to install or setup a single thing. If however you chose to install Docker, then there are a number of commands that one can run as a checklist to verify that the Docker installation was successful. We also covered how to use tools like 'grep' and 'jq' with Docker commands. Although slightly out of scope for a geting started guide, it was also demonstrated how to create aliases for Docker commands using .bashrc
and .bash_alaises
files. No getting started guide is complete without illustrating how to use the built-in help and so we covered that too. Lastly we ran a 'hello world` container as a final check to verify that Docker is installed correctly.