image
Docker Quick Start: Containerize Effortlessly.
image

Docker Quick Start Guide

Blog image

We frequently hear about Docker and how it can help in application development and deployment. Many developers find that the primary difficulty is getting started using Docker It can be confusing to distinguish between what Docker can be, and what containers are, what they do, and the role Images have, etc.

My opinion is that the best method to master Docker is to simply begin by trying the basic commands in order to become familiar with the program. This guide is to give you a brief overview of Docker and help you get started using a simple application.

What exactly is Docker? Docker is an open-source containerization system used to create, deploy and manage applications within a light virtualized environment.

Have you been through one of these situations?
You recently joined a group and need to set up your an environment for development. Reading through numerous documents, downloading different software and looking up the configurations. You can spend hours or days trying to correct the system in case you’ve missed the step or have set up an error.
Being involved in multiple projects will require you to install various versions of software and set them up so that they do not break or, even more important, manage two incompatible dependencies of packages within your computer.
You’re ready to demonstrate your app however, it won’t run on a different system. You’ve just released some feature, and it’s immediately identified as crucial by the team of testers.
Docker can help standardize the environment for development testing, deployment, etc. which can help beat problems with working on your computer phenomenon. With Docker you don’t need to install any program on your computer, aside from Docker of course. Since it’s agnostic to systems that means the same commands are available across all platforms. When compared with a VM, Docker is lighter and more efficient in terms of resource use.

Pre-requisites

Download Docker to your PC. A comprehensive guide to the process is available here.
A little knowledge of the command line
A basic understanding of any programming language

In this tutorial we’ll create an extremely basic Java application. Do not worry if you’re not a java expert but we’re making the application to print Hello World! Follow the instructions as well as download this JAR document here. this page, to run the application.

After you’ve confirmed Docker is installed and running, visit the Docker Hub and search for the ibmjava

As of the time we wrote this guide, the most current version is 8.0.7.20. We will be using the most recent version, we will
alternative version of the image, you can simply run the script below.

At the time of writing this article, the most recent version is 8.0.7.20. Because we’ll use the latest version, we’ll alternative version of the image, you can simply run the script below.

After completion, you should be able to see this image within your operating system.

Now let’s design a simple class that will print Hello World to the command line.

public class HelloWorld {public static void main (String[] args) { System.out.println(“Hello world! “);
}
}

If you’re comfortable with java, then you can compile the class and create an executable jar or download the JAR file that is available this page.

We’ll create a custom image using ibmjava for our base image and our Jar file.

We’ll begin by creating a new file Dockerfile within the application folder. Add the following lines

From IBM Java
RUN mkdir with a -p in /home/app
WORKDIR /home/app
COPY hello-world.jar .
CMD [“java”, “-jar”, “hello-world .jar”]


Let’s look at each line in detail to better understand what’s taking place.

from Ibmjava : This will use the ibmjava image we previously pulled as the base image

RUN mkdir with -p http://home/app This will create a directory that we’ll save our artifact within the container.

Workdir /home/app : This establishes our current path within the container. Going forward we will not need to specify /home/app repeatedly for any commands.

COPY hello-world.jar . This copies hello-world.jar on our machine local to the current machine.
The working directory for the container’s working directory.

CMD [“java”, “-jar”, “hello-world .jar”] : This is an entrypoint command which runs our jar file within the container after it has executed

We’ll now build the image using the following command

docker build docker build hello-world:1.0 .

It could take some time to finish and will require patience. It is possible to see something similar to this after a certain amount of time has passed.

The image we’ve chosen to name it hello-world and tagged it with 1.0Now in order to execute the application within the container, we’ll use both the name of the image as well as the tag in the same way as

The following output should be visible. output

This was a very basic usage of Docker. Now that you are familiar with Docker, go ahead and explore other great features it offers.
Read More

Leave a comment

Your email address will not be published. Required fields are marked *