While this is my 1st post on this site about Docker, and I’m sure ill write an introduction at some stage, I assume you are aware of the concepts as I have jumped straight into the CLI of Docker.
The main reason for this is to;
- Help digest the content of a course I have just been on.
- As a place for me to go as a reminder of how to use the CLI.
My intention is to start creating some ‘cheat sheets’ for the tools I use the most however I’m not too sure when I will get around to doing that.
What version of Docker am I using?
A good way to find out if you have docker installed on your Linux host would be to run the docker CLI with the --version
flag. You will also be able to find the version in case you are trying to work out if a feature isn’t working - with the speed of development its worth checking.
~$ docker --version
Docker version 1.8.3, build f4bf5c7
The following command will provide you a more detailed view of the versions. This will include the server versions and the versions that the client machine is using (i.e. where your running the CLI command).
~$ docker version
Client:
Version: 1.8.3
API version: 1.20
Go version: go1.4.2
Git commit: f4bf5c7
Built: Mon Oct 12 05:37:18 UTC 2015
OS/Arch: linux/amd64
Server:
Version: 1.8.3
API version: 1.20
Go version: go1.4.2
Git commit: f4bf5c7
Built: Mon Oct 12 05:37:18 UTC 2015
OS/Arch: linux/amd64
To obtain more detailed information on the docker installation its worth issuing the following command;
~$ docker info
Containers: 5
Images: 55
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 65
Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.13.0-57-generic
Operating System: Ubuntu 14.04.2 LTS
CPUs: 2
Total Memory: 3.848 GiB
Name: ubuntu
ID: GHFQ:64PY:KKU5:CMDW:U33C:HET4:LXJM:AKXA:BWVM:VCCL:JDR7:JMD3
Username: j051034
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
user@ubuntu:~$
Start a container
To get a container running you need to know the name of the image you want to use. In the following example this is called ‘hello-world’ (which is a nice little test for checking things are working).
You will notice that the image is not stored locally therefore docker will attempt to automatically download it form Docker Hub.
~$ docker run hello-world
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world
535020c3e8ad: Pull complete af340544ed62: Already exists
library/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.
Digest: sha256:d5fbd996e6562438f7ea5389d7da867fe58e04d581810e230df4cc073271ea52 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.
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.
Another example of running a bash shell from an Ubuntu image;
~$ docker run -it ubuntu bash
root@1cb345106008:/#
What containers do I have running?
The command to see the running containers (ie ones that are currently doing something) is as follows;
~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
You will notice that none of the containers I started are visible, this is because they are not currently running any process (I guess that’s why they used ps). To get a list of all the containers you need to use the -a
flag.
~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1cb345106008 ubuntu "bash" 5 minutes ago Exited (130) 2 minutes ago dreamy_cray
f651cb44d62d hello-world "/hello" 5 minutes ago Exited (0) 5 minutes ago romantic_bell
3e9f436bddf4 hello-world "/hello" 7 minutes ago Exited (0) 7 minutes ago evil_nobel
ae213dd41804 lab/websvr:0.2.0 "/usr/sbin/apache2 -D" 2 days ago Exited (0) 2 days ago hungry_bardeen
10ac88d595f0 lab/websvr:0.2.0 "/usr/sbin/apache2 -D" 2 days ago Exited (1) 2 days ago trusting_noyce
903368f5b954 lab/websvr:0.2.0 "/usr/sbin/apache2 -D" 2 days ago Exited (1) 2 days ago gloomy_kalam
1297734740a1 ubuntu:14.04 "/bin/bash" 2 days ago Exited (0) 2 days ago suspicious_mestorf
4efab561d52b registry "docker-registry" 2 days ago Exited (0) 2 days ago distracted_thompson
Have a look at the names of the containers, if you don’t specify one Docker will auto-assign a name. The names tend to make me chuckle a little :-). Examples form above are evil_nobel
and hungry_bardeen
.
The key value that you need to be aware of is the ID. This is the unique value which wont change, names and tags can change.
In my next post I will break down the run and ps commands in more detail.