How to deploy and run application inside the isolated docker container on CentOS and RHEL 6/7 step by step guide


Deploy and Docker run image and save new image using Docker commit|In the previous article we learned  how to install Docker on centos and redhat linux system and learned use of docker container on centos and redhat linux system. In this article we will learn how to deploy and run an application inside the docker container.

Deploy and run an application inside Docker container

In the previous article we have installed centos docker image and here we will learn Docker run image (centos based docker container) where apache service will be installed . To do this we need to execute the below command.

[root@localhost ~]# docker run centos bash -c "yum install -y httpd"

--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package             Arch          Version                    Repository   Size
================================================================================
Installing:
httpd               x86_64        2.4.6-88.el7.centos        base        2.7 M
Installing for dependencies:
apr                 x86_64        1.4.8-3.el7_4.1            base        103 k
apr-util            x86_64        1.5.2-6.el7                base         92 k
centos-logos        noarch        70.0.6-3.el7.centos        base         21 M
httpd-tools         x86_64        2.4.6-88.el7.centos        base         90 k
mailcap             noarch        2.1.41-2.el7               base         31 k

Transaction Summary
================================================================================
Install  1 Package (+5 Dependent packages)

Total download size: 24 M
How to deploy and run application inside the isolated docker container on CentOS and RHEL 6/7 step by step guide,Docker run image,Docker Commit
How to deploy and run application inside the isolated docker container on CentOS and RHEL 6/7 step by step guide

After that we need to execute the below command to know the container id.

#docker ps  -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS     PORTS               NAMES
8b451071cdd1        centos              "bash -c 'yum instal…"   3 minutes ago       Exited (0) 2 minutes ago                       agitated_hawking

Using this id we can stop , start and attach the container.



Docker Commit

We can save the new image using the container id . To save the new image we can execute the below command.To save the new image from container ID we use "Docker Commit" command.

#Docker commit <container ID> <New image neme>
# docker commit 8b451071cdd1 centos-apache
sha256:2f81cfc333d7cf8d61d3fbf21366ee1dd21f57c94bb5d7ca859ae4e99b9104c0

We can verify the new image name using the below command.

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos-apache       latest              2f81cfc333d7        33 seconds ago      305MB

Map the host container port on docker

To map the host container port we can run the below command.

 # docker run -it -p 81:80  centos-apache /bin/bash
[root@276c18a6318d /]#

After that we press ctrl+p and ctrl+q to continue the process and type the curl command on the shell to get the apache page as below.

Note: 81 is the host port and 80 is the container port.

#curl http://localhost

That’s all. If this article is helpful to know about Docker run image and save new image using Docker commit please share it!

SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

1 comments: