Understanding and using containers

Understanding and using containers

Using Docker


docker run      ubuntu  /bin/bash

nothing happened...because the container started + exited. Let's find out more.

docker ps -a

Now run the same container interactively.

docker run -it  ubuntu  /bin/bash

You are now logged in as root.

Make sure to poke around the container!

What's this docker run command doing?

run a container -t - allocate a (pseudo) tty -i - keep stdin open (so we can interact with it) ubuntu - use the Ubuntu base image /bin/bash - run the bash shell

Exit and check

docker ps -a

Grab the latest container ID and run another diff

docker diff <Container ID>)

We can see that just by logging into bash and poking around with the shell, we created a .bash_history file.

Minor changes but tracked changes never the less!

Docker tracks any changes we make to a container. In fact, Docker allows us make changes to an image, commit those changes, and then push those changes out somewhere.

This is the basis of how we can deploy with Docker.

Let's install some base items into this Ubuntu install and save it as our own base image.

Get into Bash

docker run -t -i ubuntu /bin/bash

Install some stuff

apt-get update
apt-get install -y git ack-grep curl \
        wget build-essential \


Once that finishes running and after you exit, run

docker ps -a

Grab the latest container ID and run another diff

docker diff <Container ID>


There were, of course, lots of new files added. Let's save this version of our base image so we can use it later. We'll commit these changes, name this image and tag it in one go. We'll use: docker commit :

docker commit a76b4efdb2dc cloudgenius/first:0.1

You'll get a long hash as a success message.


Let's see this image we just created. Run docker images:

docker images

You will see an output that looks something like this.

REPOSITORY                     TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
cloudgenius/first              0.1                 80dfc86d638c        42 seconds ago      429.2 MB
cloudgenius/nginx              latest              3f4c498f7fb5        58 minutes ago      208.9 MB
cloudgenius/apache             latest              f20fc3d27f66        About an hour ago   224.1 MB
google/cloud-sdk               latest              e6ffc33f566d        8 days ago          392.3 MB
cloudgenius/gcloud             latest              a400479c1ee0        3 weeks ago         424.6 MB
centos                         latest              0f73ae75014f        4 weeks ago         172.3 MB
ubuntu                         15.10               1884caeee373        5 weeks ago         131.3 MB
<none>                         <none>              14478bb0b1bf        6 weeks ago         250.3 MB
ubuntu                         latest              91e54dfb1179        6 weeks ago         188.4 MB
<none>                         <none>              ed07824ee5bd        6 weeks ago         499.6 MB
<none>                         <none>              accc5fd607bc        6 weeks ago         499.6 MB
<none>                         <none>              0443c7815164        6 weeks ago         511.8 MB
<none>                         <none>              14e15d3ad4f8        6 weeks ago         475.1 MB
<none>                         <none>              b80fa064ce4e        6 weeks ago         475.1 MB
<none>                         <none>              a3e942eba25a        6 weeks ago         487.7 MB
<none>                         <none>              b37f7d3ec146        6 weeks ago         467.7 MB
<none>                         <none>              81c1773e998b        6 weeks ago         455.2 MB
<none>                         <none>              f699a18b810b        6 weeks ago         416.8 MB
<none>                         <none>              17a85fdd5f2f        7 weeks ago         607.9 MB
wordpressstackable_wordpress   latest              cbc1b8a68fe9        7 weeks ago         305.2 MB
<none>                         <none>              8b50eccef86f        7 weeks ago         305.2 MB
<none>                         <none>              976fb2f5264c        7 weeks ago         304.4 MB
beacloudgenius/test            latest              81987af03d56        7 weeks ago         459.2 MB
<none>                         <none>              21e9bd804b0a        7 weeks ago         459.2 MB
<none>                         <none>              815fd3b7808a        7 weeks ago         459.2 MB
<none>                         <none>              4f8f22d73ac7        7 weeks ago         157.8 MB
tutum/mysql                    5.5                 5c50baf09b91        7 weeks ago         318.3 MB
ubuntu                         14.04               8251da35e7a7        8 weeks ago         188.4 MB
ubuntu-upstart                 latest              a365aaba3ebc        12 weeks ago        253.3 MB
oraclelinux                    6.6                 88c24509b051        12 weeks ago        157.8 MB
tutum/apache-php               latest              cdced04212b6        3 months ago        244.7 MB
kitematic/hello-world-nginx    latest              fa9a3bb406d3        3 months ago        7.913 MB
maxogden/gifify                latest              9cd65cf635b4        7 months ago        476.5 MB
ubuntu                         13.10               195eb90b5349        15 months ago       184.7 MB

Official Docker Slideshare.


 Cloud Genius® is a highly rated advanced technical education provider licensed by the State of Washington, USA.