Pages

Saturday, January 9, 2016

Docker - You’re first basic Docker Container

In this article we will see how we can create our first docker container. The first basic container we will create is by using the BusyBox implementation.

A BusyBox provides a fairly complete environment for any small or embedded system.
BusyBox combines tiny version of many common *nix tools and utilities into a single executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts

In order to create the first docker image use the “docker pull <ImageName>” command like below,

[root@vx111a work]# docker pull busybox
Using default tag: latest
Trying to pull repository docker.io/library/busybox ... latest: Pulling from library/busybox

5c5fb281b01e: Pull complete
fc0db02f3072: Pull complete
Digest: sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0
Status: Downloaded newer image for docker.io/busybox:latest

Once the Download is done ,we can then check out available docker images on our local machine using the “docker images”  command which will give the below output,

[root@vx111a work]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED         VIRTUAL SIZE
docker.io/busybox   latest              fc0db02f3072        4 weeks ago    1.113 MB

So we can see a “docker.io/busybox” available on our local machine with an Image ID and Virtual size. All of these commands use the image id (ex. fc0db02f3072), the image name (ex. docker.io/busybox) and the container id (ex. 72d468f455ea) interchangeably depending on the operation you are trying to do.

The Container ID is not available above as the Container is not yet started. By this point the Busy Box Image is downloaded and stored on our local machine. The next step would be to run the downloaded Image. But before that also make sure that no container is running at this moment by using the “docker ps” command. This command will show all the Up and running containers at this moment.

[root@vx111a work]# docker ps
CONTAINER ID  IMAGE  COMMAND   CREATED   STATUS   PORTS  NAMES

We can see that no Container is Up and running. To start the Container use the Image ID for the above downloaded Image and uses the “docker run” command as below.

[root@vx111a work]# docker run -it --rm fc0db02f3072
/ # uname -a
Linux 96f7152ba503 3.10.0-327.3.1.el7.x86_64 #1 SMP Wed Dec 9 14:09:15 UTC 2015 x86_64 GNU/Linux
/ #

Now once we run the docker run we will be given with a Shell prompt where we can use that to run the commands as shown above. I ran the “uname” command which gave me the necessary details. Now if we enter the exit or CTRL+C , the container will exit. In order to check the container status use the CTRL+Q and followed by CTRL+P, this will exit the container with out closing that.

Now once we are out of the Container use the same “docker ps” command to see what containers are running at this moment.

[root@vx111a work]# docker ps
CONTAINER ID   IMAGE          COMMAND  CREATED       STATUS   PORTS  NAMES
96f7152ba503    fc0db02f3072  "sh"          a minute ago  Up                    mahavira

We can see that a Container with ID#96f7152ba503   for the Image ID# fc0db02f3072   started running. The container currently is running on the Shell command and the status is Up now.

Thus we have created our first basic docker Container. We will see more details in our next articles. More to Come, Happy Learning J

No comments :

Post a Comment