Docker is a technology that allows you to run many types of applications in containers. For those of you who are not familiar with the concept of containers, I like to think of them as super lightweight VMs that do not require its own operating systems. Here’s a diagram that I made to help you understand the difference between VMs and containers. Before we get started, I suggest you to go through the Docker training on the Docker training platform to get the a good understanding of how it works.
- Ubuntu 14.04 or higher
wget -qO- https://get.docker.com | sh
sudo usermod -aG docker rjzheng
Docker has a cloud storage platform for users to store their Docker images. Sort of like Github, but they call it the Docker Hub. Go ahead and make an account so you can have a Docker ID. Docker Hub is completely free for regular users but they also offer many other features at an affordable price.
This step assumes that you have your application tested and ready to be built into a Docker image. Before running the build command, make sure to have a Dockerfile ready. Once everything is set and done, run the following command in your terminal inside of the project’s directory.
docker build -t $DOCKERID/[image_name]:[version] .
-t = tag, every image that are going to be uploaded to Docker Hub needs to be tagged by the owners Docker ID followed by the image name and image version in the above syntax.
docker push $DOCKERID/[image_name]
docker pull $DOCKERID/[image_name]
docker run -d -p [desired_port]:[exposed_port] --name [app_name] $DOCKERID/[image_name]:[version]
-d = detached, this allows the app to run in the background so the terminal wouldn’t be hung by the container process. (Note: if you don’t add -d, then the once you
-p = port, this maps the port that the application was exposed on to the port that you would like the users to have access to.
–name = name of the Docker application, Docker applications can be stopped, started, restarted, or deleted anytime, assigning a name to the container makes it easier to perform those tasks.
Here you have a running Docker application and you can monitor all of your Docker containers by running
docker container ps
For more docker related commands and information, docker provides a very detailed documentation.