Our first containers
- Hello World
- That was our first container!
- A more useful container
- Do something in our container
- Install a package in our container
- Try to run our freshly installed program
- Counting packages in the container
- Counting packages on the host
- Comparing the container and the host
- Host and containers are independent things
- Where's our container?
- Starting another container
At the end of this lesson, you will have:
Seen Docker in action.
Started your first containers.
In your Docker environment, just run the following command:
$ docker run busybox echo hello world hello world
(If your Docker install is brand new, you will also see a few extra lines,
corresponding to the download of the
That was our first container!
We used one of the smallest, simplest images available:
busyboxis typically used in embedded systems (phones, routers...)
We ran a single process and echo'ed
A more useful container
Let's run a more exciting container:
$ docker run -it ubuntu root@04c0bb0a6c07:/#
This is a brand new container.
It runs a bare-bones, no-frills
-itis shorthand for
-itells Docker to connect us to the container's stdin.
-ttells Docker that we want a pseudo-terminal.
Do something in our container
Try to run
figlet in our container.
root@04c0bb0a6c07:/# figlet hello bash: figlet: command not found
Alright, we need to install it.
Install a package in our container
figlet, so let's install it:
root@04c0bb0a6c07:/# apt-get update ... Fetched 1514 kB in 14s (103 kB/s) Reading package lists... Done root@04c0bb0a6c07:/# apt-get install figlet Reading package lists... Done ...
One minute later,
figlet is installed!
Try to run our freshly installed program
figlet program takes a message as parameter.
root@04c0bb0a6c07:/# figlet hello _ _ _ | |__ ___| | | ___ | '_ \ / _ \ | |/ _ \ | | | | __/ | | (_) | |_| |_|\___|_|_|\___/
Counting packages in the container
Let's check how many packages are installed there.
root@04c0bb0a6c07:/# dpkg -l | wc -l 190
dpkg -llists the packages installed in our container
wc -lcounts them
How many packages do we have on our host?
Counting packages on the host
Exit the container by logging out of the shell, like you would usually do.
Now, try to:
dpkg -l | wc -l. How many packages are installed?
figlet. Does that work?
Comparing the container and the host
Exit the container by logging out of the shell, with
Now try to run
figlet. Does that work?
(It shouldn't; except if, by coincidence, you are running on a machine where figlet was installed before.)
Host and containers are independent things
We ran an
ubuntucontainer on an Linux/Windows/macOS host.
They have different, independent packages.
Installing something on the host doesn't expose it to the container.
Even if both the host and the container have the same Linux distro!
We can run any container on any host.
(One exception: Windows containers cannot run on Linux machines; at least not yet.)
Where's our container?
Our container is now in a stopped state.
It still exists on disk, but all compute resources have been freed up.
We will see later how to get back to that container.
Starting another container
What if we start a new container, and try to run
$ docker run -it ubuntu root@b13c164401fb:/# figlet bash: figlet: command not found
We started a brand new container.
The basic Ubuntu image was used, and
figletis not here.
We will see in the next chapters how to bake a custom image with