Introduction to Docker - Day 2

For second day of Introduction to Docker, we will learn how to run the docker test app with name option. After that, we discuss about pulling an actual docker application and we will learn the naming convention of docker image.


Run with Name Option

We start by running hello-world app without any option. Run the test app as follows:

docker run hello-world

List the container:

docker container ls -a

The result should be as follows:



We then remove the container using the ID or the name cranky_brahmagupta. This name is created randomly by the system if we failed to supply a name.

Now, we remove the container as follows:

docker rm cranky_brahmagupta

To run the container and supply a name, we use the option --name follow by a single space and the custom name. See example below:


docker run --name simple hello-world



List the container

docker container ls -a

The result is as follows:


Please note that the name of the container will be the name that we supplied. We can remove the container using the name.


docker rm simple


Pull Docker Image

As we have mentioned in the previous post, a docker image contains a single app. Docker.com supply many apps such as Wordpress, mySQL, MongoDB, Python, CentOS, Alpine (light-weight Linux) and Ubuntu.

We can download these image first before running it. We use the pull command to download image without running it.


docker pull ubuntu

The result is as follow


As you can see, if we just use the image name ubuntu, the system will post fix the image name with a tag :latest.

We can try pulling other OS such as CentOS and Alpine. As we can see, Alpine has the smallest image size whereas CentOS takes up 200MB.

Feel free to try the following example:

docker pull alpine
docker pull hello-world
docker pull ubuntu
docker pull centos
docker pull python


Docker Image Tag

Docker uses tag to further differential different image with a same name. For example, if you search for python image for docker, it contains many version of python.

If we pull python:latest, the image will include both python2  and python3. We can download a specific version of python using different tag. On the docker for python webpage, there are many tags. The screenshot below is just a portion of the tag.


We can even download older version of Python using the tag.

Now, lets pull the slim version of Python 3 using the command below


docker pull python:3.7-slim


Resulting screenshot is as follows:



This image is much smaller than the default image python:latest. The default version contain both Python2 and Python3. The slim 3.7 version only contain Python 3.7 without any additional libraries.


Community Docker Image

There are also community developed docker images. The name of these images are prefix by their user account. For example, Google also supply docker image for its machine learning platform Tensorflow. The name of the image is tensorflow/tensorflow. The first tensorflow is the name of the account, the second name is the name of image.

Once you have your own docker account, you can create your own docker image. Let's say you have created your own version of hello-world. To identify and differentiate your version against the official version, we name the image as <username>/hello-world. So to pull an image not developed by Docker.com, we use the naming convention mentioned above.

Now we pull Tensorflow as follows:

docker pull tensorflow/tensorflow

Resulting screenshot as follows:



Managing Images

Please note that all these images takes up hard disk space. To check how big the image size, use the command below:

docker images

We can remove unused docker image using the following command:

docker image rm <image_name>
# Alternatively
docker rmi <image_name>

Please also note that if you have more than one image with the same image name, we must include the tag. Otherwise, the system will remove the image with default tag "latest". Please also note that you need to remove the related container first before you can remove the image.


***







Comments

Popular posts from this blog

Revive Old Mac Mini (2009) with Linux

Configure Unattended Upgrades on Raspberry Pi

Install and Configure RealVNC in Linux Ubuntu 18.04 LTS