Search code examples
dockerdockerfiledevopsdocker-machine

Dockerizing a Web Application


I am new to this Containerization and I was wondering how Docker could replace Virtual machines?

I am given a case study in which there are 2 virtual machines each acting as a virtual server, one is a Development server and the other is a Test Server and I am asked to study how Docker could help in managing the workflow efficiently.

In this case the 2 virtual Machines are Servers and the idea of Docker replacing virtual machines is confusing me.

can anyone help me understand this concept.

Thanks in Advance!!


Solution

  • I am not sure how a server can be completely replaced by a docker container, so I am assuming you want to replace an 2 applications running in 2 servers into 1 server running 2 containers of each test and dev apps.

    I am going to make a few assumptions before I can answer.

    • First I am going to assume, your application is a simple web service that has been deployed on a tomcat/IBM websphere in the server.
    • Secondly, I am assuming the databases are on a different server for both test and dev servers.

    Docker Basics

    1. Dockerfile - USing the command docker build, you can create an image
    2. Docker Image - This is created from a dockerfile
    3. Docker Container - When you do a docker run of an image, a container gets created. A running instance of an image is your container
    4. Docker Registry - The place from where you can download base images So here it goes,

    5. Setup docker on a unix server.

    6. Now you need to create 2 containers which will host identical apps. For this, you first need to write a dockerfile, create an image and then start the container using the image.

    A sample dockerfile would look like something below

    FROM webspher-liberty17:webProfile7
    
    ENV SERVER_NAME=myapptestserver
    
    RUN ["/bin/bash", "-c", "/opt/ibm/wlp/bin/server create $SERVER_NAME"]
    
    EXPOSE 9080 9443
    
    
    COPY server.xml jvm.options /opt/ibm/wlp/usr/servers/$SERVER_NAME/
    COPY *.war /opt/ibm/wlp/usr/servers/$SERVER_NAME/dropins/
    
    CMD ["/opt/ibm/docker/docker-server", "run", "myapptestserver"]
    

    Now when you do a docker build of this docker file, it would create an image with base layer as ibm liberty. Every command after the FROM allows you to add an additional layer, so you can customize to your specifics.

    Once you have done the above for both your apps, you practically have two variants of your app running on same server but serving two different environments.

    Best part, add this to your CI/CD pipeline in bamboo/jenkins, and you can bring up and down environments in a jiffy.