In my previous post I provided some overview about Docker and it’s integration with OpenStack, containers and the related technologies – cgroups and namespaces. In this post I’ll go through some very basic commands using Docker.
Downloading and Installing Docker
As Docker rely on the kernel running on your machine make sure you are running 3.10 at minimum.
uname -r can help you determine what kernel is running on your machine.
Before downloading Docker it is important to mention that a relatively new Linux distribution called CoreOS has Docker installed out-of-the-box and provides some additional benefits to Docker users. Find more about CoreOS at its Wiki page. You can read more about CoreOS and its Docker integration here.
I’ll describe briefly my personal experience with downloading and installing Docker on Ubuntu 14.04. The official installation guide can be found at Docker’s website.
Using Ubuntu 14.04 I had no prerequisite to take care of.
ubuntu@docker-instance2:~$ wget -qO- https://get.docker.com/ | sh modprobe: FATAL: Module aufs not found.
Few seconds later and you are done with this displayed:
If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like: sudo usermod -aG docker ubuntu Remember that you will have to log out and back in for this to take effect!
In order to get rid from using
sudo every time you run a
docker command I followed the above instructions to include the user
ubuntu in the
docker group. More info about that can be found here.
ubuntu@docker-instance2:~$ sudo usermod -aG docker ubuntu
It’s time to spin up our first Docker container.
Basic Docker Usage
You can learn a lot by simply executing the following basic command
ubuntu@docker-instance2:~$ docker run hello-world Unable to find image 'hello-world:latest' locally 511136ea3c5a: Pull complete 31cbccb51277: Pull complete e45a5af57b00: Pull complete hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security. Status: Downloaded newer image for hello-world:latest Hello from Docker. This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (Assuming it was not already locally available.) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash For more examples and ideas, visit: http://docs.docker.com/userguide/
Pretty great interaction, ah? So we learned that the docker deamon fetched the “hello-world” image for the Docker Hub which is where you can download and upload Docker images. Later on the deamon created a container that executed
Hello from Docker print on your terminal. Note that a container run as long as there’s an active process in it. In or case the container that has just been created is in stopped mode until we start it again. Thus,
docker ps will show nothing at all
ubuntu@docker-instance2:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker info indicates that 1 container exist.
ubuntu@docker-instance2:~$ docker info Containers: 1 Images: 3 Storage Driver: aufs Root Dir: /var/lib/docker/aufs Backing Filesystem: extfs Dirs: 5 Execution Driver: native-0.2 Kernel Version: 3.13.0-46-generic Operating System: Ubuntu 14.04.2 LTS CPUs: 1 Total Memory: 1.955 GiB Name: docker-instance2 ID: U4NR:EOLW:C43D:PO6T:MCVH:HXUY:HZ3N:M5UD:5MJU:42O2:BQCS:5QHB WARNING: No swap limit support
We can also launch an interactive container allowing us to run commands inside the Docker container. More about that and other options Docker provide you can find at this guide from Docker.
ifconfig inside a container right after creating interactive container looks like this:
ubuntu@docker-instance2:~$ sudo docker run -ti ubuntu:14.04 /bin/bash Unable to find image 'ubuntu:14.04' locally f3c84ac3a053: Pull complete f3c84ac3a053: Download complete a1a958a24818: Download complete 9fec74352904: Download complete d0955f21bf24: Download complete 511136ea3c5a: Download complete Status: Downloaded newer image for ubuntu:14.04 root@c1404d96dd72:/# ifconfig eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:03 inet addr:172.17.0.3 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::42:acff:fe11:3/64 Scope:Link UP BROADCAST RUNNING MTU:1450 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:648 (648.0 B) TX bytes:648 (648.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Having this in mind we can exit the container and execute
ifconfig on the host machine
ubuntu@docker-instance2:~$ ifconfig docker0 Link encap:Ethernet HWaddr 56:84:7a:fe:97:99 inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::5484:7aff:fefe:9799/64 Scope:Link UP BROADCAST MULTICAST MTU:1450 Metric:1 RX packets:1 errors:0 dropped:0 overruns:0 frame:0 TX packets:3 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:76 (76.0 B) TX bytes:258 (258.0 B) eth0 Link encap:Ethernet HWaddr fa:16:3e:d5:3a:ee inet addr:192.168.1.11 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::f816:3eff:fed5:3aee/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1 RX packets:47377 errors:0 dropped:0 overruns:0 frame:0 TX packets:12971 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:65798713 (65.7 MB) TX bytes:1103464 (1.1 MB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
We see that there is a difference between the interfaces the container is having versus and the ones found in the host machine. We can also notice
docker0 interface. More about that in the next post – Docker Networking.