Docker. Docker. Docker. Docker is one of my favorite things to talk about. For those of you working in the Cloud space or working with any form of Cloud technologies, you probably encounter Docker talk and/or articles about Docker on a daily basis. Docker is an extremely interesting new cloud and container technology that I believe will change the way that people develop, deploy and scale. At the time of this article it is one of the most popular cloud and open source project on the market and it is still very early in its lifetime. In this post Ill talk about what the Docker technology is, how Docker containers are different that LXC containers. Ill also talk about the advantages of Docker over other container technologies. NOTE: All demonstrations will be done on a CentOS 7 server. If you are interested in Learning Docker or even looking to continue your knowledge, I highly recommend reading "The Docker Book" by James Turnbull (extremely intelligent open source author). I would also recommend following his blog.
What is Docker?
Docker is an open source Linux container technology (originally based on the LXC project) that is used to build, ship and deploy distributed applications. Docker was built on the basis of providing developers with a simple way to build and quickly deploy lightweight applications from anywhere and run exactly the same in any environment in the development life cycle. As with LXC, the only thing you need in order to run these containers is a Linux kernel allowing Docker to be extremely portable. I would also argue that another important factor of Docker is that is it built to allow for developers to quickly scale their environments when needed.
Docker consists of the following 4 main components in order to operate. Each explained short below:
- Docker Daemon - The Docker daemon runs on a host server and does all the work of running, shipping and building containers. The Docker daemon runs as a service on the Linux host.
- Docker Images - The underlying source code for the containers and tells the containers how to be built.
- Registry - There are 2 types of registries in the Docker world, Public and Private. A registry is basically a storage repo of your Docker images that you build. You pull down images from here.
- Docker Container - The final product from all other components from above. The image, the operations and the environment.
Docker is built with the idea of making SysAdmin's and developer's lives easier!
How is it different from LXC?
The LXC project is not a new technology and has been around for several years whereas Docker has only been in the wild for about 1.5 years or so from the time of this post. I describe each technology as so: LXC is Linux container technology that essentially gives you a lightweight container in the form of a full blown Linux Operating System whereas Docker is a Linux container technology that containerizes simply single application processes. In short I think of LXC as being a containerized Linux OS and Docker as a containerized application. Both are awesome and lightweight. One should not be thought of as being better than the other. The technologies seem to be the same but there are situations where you would chose one of the other.
Advantages/Features of Docker
As part of the introduction I would like talk about what I believe to be key features and advantages of using Docker. All of the advantages/features play nicely together which makes Docker such a monster.
- Scalability - because containers are lightweight and minimal, Linux containers can be deployed in a matter of seconds. Due to the rapid deployment capabilities you are able to quickly scale your app during high load or heavy traffic occurrences.
- Portability - since the container and its dependencies are not reliant on the host, the container can be "shipped" and run across any Linux host that operates Docker daemon.
- Reproducible – I think this is important aspect of Docker and plays off of the portability factor as well. Docker allows for users to deploy an app on their laptop or in dev and move it to production and expect to have the same results. Since containers don’t rely on dependencies etc they will run the same anywhere.
- Isolation – the use a cgroups and namespacing from the Linux kernel allows 100’s to 1000’s of Docker containers run on the same host or across a cluster of hosts without bumping into one another or affect the performance of other containers.
- Sharing – whether deciding to use public or private registries for your images, you can share you development with virtually anyone on the planet and collaborate on projects.
- Lightweight – one of the purposes of Docker is to be minimal and no overhead which in turn allows for extremely fast deployment and scaling abilities.
- Version control – Docker is extremely “Git”-like. Docker registries keeps track of versions, differences, and allows for simple rollback.
- Open Source and Community – Threw this one in last. Honestly, what is better than open source? Docker has a major backed open source community that is absolutely taking this technology to a revolutionary state that will in my opinion change the way we develop and run applications. Its incredible in my opinion how much attention this technology has gotten in its early stages and I am extremely excited for the future.
Common Commands
Here is a cheatsheet of common Docker commands that will frequently be used when first starting out.
Display system-wide information about your Docker environment.
docker info
Pull an image from your repo to the host.
docker pull IMAGE_NAME
List the images installed on your system.
docker images
Remove an image.
docker rmi IMAGE_ID
List all the containers.
docker ps -a
Remove a container.
docker rm CONTAINER_ID
Start/Stop a container. Tons and Tons of options that wont be mentioned. Also you can restart an already running container with "restart".
docker start|stop|restart CONTAINER_ID
Run a container. Note that the following command will create a new container each time. If you just want to run a stopped container then use "docker start container". Also without the "-d" option at the end of the command you will be attached automatically.
docker run -i -t BASE_IMAGE COMMAND -d
See additional information about a container or image. Tons more info that be presented such as IP addresses etc.
docker inspect CONTAINER_ID|IMAGE_ID
List and see information on running containers.
docker psInstalling Docker on CentOS 7 and "Hello World"
For CentOS 7, Docker comes as default. If it does not for some reason you can get it from the epel repository. Once you have the repo run the following:
# yum install -y docker docker-registry
Since Docker is reliant on a Docker daemon to run, pull, ship etc., lets go ahead and start the Docker daemon and enable it to start at boot so its running default.
# systemctl start docker
# systemctl enable docker
Lets go ahead and pull down the centos images from the docker hub and verify its there.
# docker pull centos
# docker images
Let's create our very first container from the centos image. We will create that very first, everyone's favorite, "Hello World!" app.
# docker run -i -t centos /bin/echo 'Hello World!'
OUTPUT:
Hello World!
Ending Notes
This was an extremely short intro to Docker and probably a little boring if you have worked with Docker before. The upcoming blog posts will go much further in depth with things such as building your own images, private repositories, orchestration and so on. Cheers.
Blog Series on Linux Containers:
Previous Post: LXC Advanced Configuration
Next Post: Building Docker Images
Previous Post: LXC Advanced Configuration
Next Post: Building Docker Images
No comments:
Post a Comment