This learning lab will introduce you to Docker, a common toolchain for building, sharing and deploying containers. We would recommend you read the Containers-101 lab first, then you can put your new knowledge into practice here by building, deploying (and optionally sharing) your first Docker container.
Completion time: 20 minutes
- DevOps engineers
- Application developers
- IT teams addressing the developer need for Docker and Containers
Some content for this learning lab comes with thanks from the Cisco Live EU 2017 workshop "Introduction to Containers". Further reading links are from the excellent docker introduction at imapex.io
As we covered in the Container-101 learning lab. The technology underpinning containers is only part of the story, Containers are popular because of the tools and workflows built around the technology, focused on making it easy for developers to build, package, share and deploy their applications. Docker the most popular one of these toolchains designed to do just that, but there are others.
- A way to package up our applications and dependencies.
- A way to guarantee execution consistency and portability.
- A way to keep your applications isolated.
- A way to use your compute resources without the overhead of VM’s.
Containers ARE NOT
1. Microservices We hear containers and microservices used a lot together. Microservices benefit from a lightweight packaging, distribution and deployment solution. However, you can put package anything into a container, including a badly written legacy app in some cases, using containers doesn’t magically make bad code better. 2. Virtual machines Sounds obvious, but worth remembering they are different. Containers are purely user-space, if you need kernel extensions/modules or a custom kernel, containers probably aren't what you’re looking for. 3. Magic They bring their own nuances and require deployment consideration just like any other toolchain.
So lets get started with the hands on!
The docker engine (run's and manages the containers on a host) and the docker client tools (allows you to interact with the engine, build, run and share docker images) are now in the default package management on many linux distributions.
You can also download direct for Linux, Mac and Windows from Docker.com if you are having issues..
However, for these hands on sessions. we'll use an in-browser docker playground called play-with-docker.com
This gives you access to a full VM running Docker, direct from your web browser, making demo's really easy regardless of your device!
Open http://play-with-docker.com in your browser and click "Add New Instance" on the right. You'll then be given a full terminal window to the instance which we'll use for the rest of this learning lab!
On this VM, docker has already been installed. You can test this now by asking the docker CLI for it's version number..
Output will look something like this:
Docker version 1.13.1-rc1, build 2527cfc
Running our first Docker container
The simplest way to use docker is to run an existing 'public image' someone else has already created and shared on the public Docker Hub.
The docker CLI searches docker hub by default (other private docker repositories are available and can be configured for the docker CLI to use those instead).
Search for a public docker container image by running
docker search <keyword>
Theres a very simple test container called hello-world... Guess what it does.
We can see docker has searched the public docker hub repositories and found the hello-world image. So lets run it...
docker run hello-world
When we specify an image name (hello-world in this case), docker looks to see if we have a copy of that container image locally, if we don't, it downloads it from the public docker hub.
Once downloaded, docker will set up the needed container isolation on the system and run this container image.
This container simply outputs a hello message to the console and then dies... You should see this happening on your play-with-docker system:
Congratulations! You just ran your first container with Docker!
Read on to find out what just happened behind the scenes, and how we make our own Docker images to containerise our own applications!