How to create docker container

Date posted : 28/12/2018

What is Docker ?

Docker is a containerization platform that packages your application and all its dependencies together in the form of a docker container to ensure that your application works seamlessly in any environment.

What is Container ?

Docker Container is a standardized unit which can be created on the fly to deploy a particular application or environment. It could be an Ubuntu container, CentOs container, etc. to full-fill the requirement from an operating system point of view. Also, it could be an application oriented container like CakePHP container or a Tomcat-Ubuntu container etc.

Prerequisites

  1. Install Docker and enable the service.
https://blog.pheonixsolutions.com/how-to-install-docker-in-centos-7/
This above blog will helpful for installing Docker in centos 7 linux platform.

2. Check the disk- space availability of our system.

# df -h 

3. Check the Process status of Docker.[Running status of Docker]

docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED                                                                                                                          STATUS              PORTS               NAMES


Create Docker Images and Containerization.

Step 1 : . Pull your required Os( 1st centos) for Docker Images. [Pull images from docker Hub]

docker pull centos
latest: Pulling from library/centos
a02a4930cb5d: Pull complete

Status: Downloaded newer image for centos:latest

Step 2 : Check the Docker image whether it is pulled.

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              1e1148e4cc2c        13 days ago         202MB

Step 3. Pull your required Os( 2nd Ubuntu) for Docker Images. [Pull images from Docker images]

docker pull ubuntu

Status: Downloaded newer image for ubuntu:latest

Step 4. Check the Docker images to know Image id and whether it is pulled.

 docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              1e1148e4cc2c        13 days ago         202MB
ubuntu              latest              93fd78260bd1        4 weeks ago         86.2MB

Step 5: Run a docker in detach mode, to create a container in your own names. (Note: for Centos)

Here, we have created a container in name of XYZ, replace of it in your convenience.

docker run -itd --name=xyz  centos:latest /bin/bash
667db752093100944df883d799a8d4f09564669f061362e614364d4a319e8529

Step 6: Check the Running status of the Docker .

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
667db7520931        centos:latest       "/bin/bash"         10 seconds ago      Up 9 seconds                     xyz

Step 7:Run a docker in detach mode, to create a container in your own names. (Note: for Ubuntu)

 docker run -itd --name=abc  ubuntu:latest /bin/bash 95dad75e0c6ccd1330053d0e5aff19b42fd67d22dcb7b52d62e503a79624a11b 

Step 8 : Check the Docker Running status of it with names, container Id, Image, status and ports.

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
95dad75e0c6c        ubuntu:latest       "/bin/bash"         5 seconds ago       Up 4 seconds                            abc
667db7520931        centos:latest       "/bin/bash"         58 seconds ago      Up 57 seconds                           xyz

Step 9:Execute the running container .( for XYZ , centos). It will enter in to a container.

docker exec -it xyz /bin/bash

Now you are Inside the container.

Step 10 : Check the os version in etc directory.

cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"

Step 11: Exit the container.

 #Exit

Now check the running container progress once.

# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
95dad75e0c6c        ubuntu: latest       "/bin/bash"         9 minutes ago       Up 9 minutes                            abc
667db7520931        centos: latest       "/bin/bash"         10 minutes ago      Up 10 minutes                           xyz

Step 12: Execute the running container .( for abc container, Ubuntu). It will enter in to a container.

docker exec -it abc /bin/bash

Step 13: Check the os version in etc directory.

# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"

Step 14 : Exit the container

# Exit

This article helps you to guide in creating a Docker image and container in a easy manner.

Leave a Reply