In our high level overview we talked briefly about Linux containers, and that’s what Docker is all about: Containers.
A container is a self-contained application that runs on a shared kernel. Docker containers are no different. When you run an image, you are creating a container that has followed all of the instructions in your Dockerfile to become an application. This can be something as small as a line of code that spouts out Hello, world!
to a fully functional operating system with everything one may need to develop a complex application in a compiled language and test it.
Some things to note:
In contrast to a Virtual Machine, a container is much smaller and easier to spin up, often in a matter of seconds.
In the previous section we talked about images and how they form the blueprints for containers by following the instructions within a Dockerfile or similar. Now we’re going to run a few examples of spinning up containers.
Let’s take the image we created in our last step and spin up a container. From within the ~/projects/docksal-training-docker/
folder we used in the last step we’re going to now run the container.
Enter the following in your terminal:
$ docker run -i -t \
--name=test_container \
image-example:1.0.0 /bin/bash
This will start the container and allow us to use the command line from within the container. Go ahead and poke around a bit. It’s a fully functional Ubuntu install within a container on your host machine that took only a few seconds to setup!
When you’re done, you can exit the container by entering exit
at the command line. This will also stop the container.
Up next, we’re going to explore storage options for containers.