Docker in 3 steps
Docker enables containerization of Software Applications. It is a computer program which provides operating system level virtualization. It is very helpful in building, deploying and running of application. Containers are used for shipping goods, docker provides similar service for application. While it is a powerful platform, it is surprisingly simple to integrate. In this post I will go over 3 steps to containerize an application using Docker.
Precondition
Already have a self contained Java 8 application myapp.jar, not going into details of creating a micro service application. Lot of literature could be found over the net, for example you can reference RESTful Web service spring boot app.
Create Dockerfile
It is very simple to containerize any application with Docker. The definition of Container goes in Dockerfile. A Dockerfile might look like this, please take note of comments:
#Use Java 8 Image
FROM dockerfile/java:oracle-java8
#Set the working directory
WORKDIR /app
#Copy target directory contents to working directory
COPY ./target /app
#Make port 8080 available to the outside world
EXPOSE 8080
#Run jar file when container launches
CMD ["java", "-jar", "app/myapp.jar"]
Build Image
Building of Docker image could be done by running the build command. A friendly name could be given with -t flag as shown below.
docker build -t mydockerapp .
Check your image
$ docker image ls
REPOSITORY TAG IMAGE ID
mydockerapp latest 123456cea798
Run Application
Run app using run command, use -p flag to map machine’s port 5000 to the container’s published port 8080:
docker run -p 5000:8080 mydockerapp
This should start the Docker container and the application should be accessible at port 5000.
Final Note
As you can see containerization of any application is fairly straight forward. Docker is opensource and lot of documentation could be found over the internet. My intention here is to highlight the simplicity of this powerful platform. If you find this helpful then please share your thoughts.