How To Perform Task like Install, Run and Delete Applications Inside Docker Containers - Part 4
Docker Linux Tutorials

Learn To Install, Run And Delete Applications Inside Docker Containers – Part 4

In the tutorial, we will learn to perform some important task like Install, Run and Delete Applications Inside Docker Containers. Here we will use most of the commands which were used in PART 3A and Part 3B.

Just in case, if  you did miss Previous tutorials regarding Docker , You can  read here:

Part 1: What Is Docker And Concept Of Containers With Virtualization?
Part 2: How To Install Docker On CentOS/RHEL 6/7? And Learn Docker HUB Registration
Part 3A: Getting Familiar With Docker Commands Docker Terms: Docker – Part 3 A
Part 3B: Getting Familiar With Docker Commands Docker Terms: Docker – Part 3 B

Scenario :

Host OS: CentOS 7 x86_64
Host IP: 192.168.1.188
RAM: 4GB memory,
Network Port:  1GB/s
HDD: 1000GB of disk space.

In this Article, we will run a CentOs based Docker container and we will install Apache Web server. We will also commit these changes to the container. In short, we will Docker container into a new image, remove a container and run an Apache web server inside a container.

So Let’s Start

1. Start Container

First, start the container and with the help of the following command get the ContainerID

As you have got a ContainrID but as you can see it’s in Exited State.


2. Install A Service In Container

To install a service or the packages we need to start this container and get attached to it. We get access inside container we can do lots of work. For this example, we will install Apache Deamon.

First Start The Docker Container Using Container ID

Now As you can see Docker Container has started and now we will do our service installation.

We have Successfully Installed A service Inside The Container.

3. Commit Changes To The Container

As we a have container with Apache installed inside. Now we will commit this container a new Image and we will save this as our new Docker Image. First, We need to get exit from this Container and then follow more steps.

Here, 7d81872f6a2b is Container ID and centos-apache is our new Image. Now we can confirm that we have a new image by the following command.

4. Verifying Image With Installed Apache

Now we can test our newly created image and check that all the changes we did commit inside. In this case, Apache service has been installed), so execute the following command in order to generate a new container, and tell us that we have installed Apache

5. Removing A Container

Now we will remove this container because we don’t need it and to do the same, we require contained ID so run following command to get ContainerID and delete that container.



6. Running A Sevice Inside Container

Now we have our own image and we want to run Apache server from our new docker image centos-apache and to do that first thing we need to do is to create a new container now along with we will map host-container ports and enter container shell by issuing following command.

-p option is to open host port to container port( host port can be arbitrary and no other host services should listen to it), the container port must be exactly the port that the inside daemon is listening to.
Ctrl-p + Ctrl-q keys are used to detach container from console.

Now we can check work and get the state of your running container with following commands

OR

7. Check Your Work

In order to visit the page served by the Apache Container, open a browser your LAN and type the IP address of your machine using the HTTP protocol.

How To Perform Task like Install, Run and Delete Applications Inside Docker Containers - Part 4

Here You Can see its working on port 81

8. Stop A Container

We have learned most of the basic operation on Docker now this is the final step To stop the container. To do that run the following command followed by container ID or name.

Part 1: What Is Docker And Concept Of Containers With Virtualization?
Part 2: How To Install Docker On CentOS/RHEL 6/7? And Learn Docker HUB Registration
Part 3A: Getting Familiar With Docker Commands Docker Terms: Docker – Part 3 A
Part 3B: Getting Familiar With Docker Commands Docker Terms: Docker – Part 3 B


Watch Video: And Subscribe To My YouTube Channel

Subscribe on Youtube

In case, if you are having anyone trouble in this tut please let me know by commenting and please share this article with your friends.

Kapendra
Love to write technical stuff with personal experience as I am working as a Sr. Linux Admin. and every day is a learning day and Trust me being tech geek is really cool.
http://kapendra.com

Leave a Reply