Introduction to Docker Day 5

On day 5, we will focus on running base OS such as ubuntu, CentOS and Alpine. We will also learn how to reuse exited container. Finally, we will learn how to convert the container into images.

Running Base OS

To run base OS in a container, use one of the following command:


docker run --name ubuntuwithpython3 -it ubuntu


Next, we would like to perform system update and then install Python3 using the following command:


apt-get update
apt-get upgrade
apt-get install python3
exit


We can explore various base os. Base os are the os which the docker image is build on. Many OS vendor are racing to build the base os with the smallest size.


docker run -it ubuntu
docker run -it centos
docker run -it debian
docker run -it alpine
docker run -it busybox
docker run -it fedora /bin/bash

Most OS will default to shell. however, for Fedora we must specify the shell path. Exit the base OS when done.


Continue Exited Container

In the last section, we have install Python 3 on Ubuntu. Unfortunately, we have exited the container. Do we need to rebuild Python 3 again? The answer is NO. We can continue exited container using the command syntax below:


docker start -a -i <container_name_or_id>

So for the previous exercise, use the following command: 


docker start -a -i ubuntuwithpython3


We can continue to install pip and add 2 Python library Numpy and Scipy.

apt-get update
apt-get upgrade
apt-get install python3-pip
pip3 install numpy
pip3 install scipy
exit


We can also continue with any exited container using docker start command.

Convert Container to Image

Following up with the previous example, if we are satisfy with the installation, we can convert the container into image. This way when we prune our container, our image is still being preserve.

Using the following command to convert the container into image:


docker commit ubuntuwithpython3 mypython3withscipy


Note:
  • Image name must be in small letters
  • Tag optional, the default is :latest
Note: The above method is not a standard way to build docker image. However, we can use the method above to test our docker file installation process. Once we have refine our installation process, we can build aa docker image using a build file.

In the next session, we will learn how to build a docker image using docker file.


***

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