Why Docker and What is Docker?

UPDATED: 10 November 2019
docker logo

Why Docker?
As a developer, Have you ever run into situations like...

  • Code is working in local system, ain't working on production/staging server.
  • Software(apache, php, etc...) upgrade on production/staging server crashed your code.
  • Require separate environment of your website/server to test newly developed feature.
All these problems of Software Development Life Cycle (SDLC) can be solved by docker. Now lets see...

What is Docker?
Docker is like virtual machine but unlike virtual machine, docker don't need separate Operating System on top of Host Operating System. Docker uses Host Operating System directly via Docker Engine to run applications.

Docker Containers vs Virtual Machines

How Software Development Life Cycle (SDLC) problems can be solved?
Using DockerFile, write your application specific environment to run.

What is DockerFile?
File contains environment specific configuration like: for development, for testing, for production, for release_v2.3.1, etc... This can be further drilled down as per your micro-services like...

  • dev-inventory-ui-php
  • dev-inventory-backend-java
  • dev-salesorder-ui-react
  • dev-salesorder-backend-spring

Sample docker file. No extension is required for this file.
FROM openjdk:8-jre
ADD your-app-main-1.0.jar destination-file-docker-app.jar
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /destination-file-docker-app.jar
Docker in action
On local system you developed your application with Java version 8 now specify same version in DockerFile. Image built/created from this DockerFile will run Java version 8 in Container. So application will work as expected.

Now say if you upgrade your code for Java version 9. All you need to do is just update your DockerFile's Java version to 9. Docker will check that Java version 9 is needed and not available so it'll download Java version 9 and then run your application.

Lets say something goes wrong then you can launch container from your previous DockerImage of Java version 8. And you application is downgraded, no need to uninstall Java version 9 or any other software you added with new DockerFile.

By just writing DockerFile you can control your application's execution environment from local to development and development to production. You can also create multiple DockerFile for different environments as per your requirements.

  • Code execution will be same as local for production server.
  • This way you don't need to worry about upgrading/downgrading your server's environment.
  • Also same DockerImage can be used to launch new service. Docker will download all required software on server that are mentioned DockerFile. No overhead of configuring server for launching new service.

Advantages of Docker

  • Light weight compare to virtual machine.
  • Same DockerImage can run on local, Kubernetes, Amazon Web Service, Google Cloud, Microsoft Azure or any other cloud platform without changing anything in DockerFile.
  • Quickly start your application in Docker.

Other References:
How to run MySQL Server in docker?