Install Kafka Docker

  



Mac & Windows: install the Docker Toolbox to get Docker installed. As the generated files are in your shared folder, they will not be deleted if you stop your Docker container. However, if you don’t want Docker to keep downloading all the Maven and NPM dependencies every time you start the container, you should commit its state or mount a volume. The latest kafkacat docker image is edenhill/kafkacat:1.6.0, there's also Confluent's kafkacat docker images on Docker Hub. If you are connecting to Kafka brokers also running on Docker you should specify the network name as part of the docker run command using the -network parameter.

  1. Install Kafka Docker Command
  2. Install Kafka Docker Commands
  3. Install Kafka Docker Centos

Docker Java Example

Install Kafka Docker

We shall learn following items in this Docker Java Example :

Build Docker Image with Java Application

1. Create a directory

DockerInstall kafka docker vpn

A separate directory is useful to organise docker applications. For this Java Example, create a directory somewhere with name of your choice. We shall use the name java-application

2. Create Java Application

Install confluent kafka docker

Create a simple Java File, in the directory java-application, with name HelloWorld.java containing the following content.

3. Dockerfile

Create a file with name Dockerfile. Dockerfile contains instructions to prepare Docker image with our Java Application.

Following is the content of Dockerfile.

4. Verify contents of java-application directory

5. Build docker image

Login as root user. Navigate into java-application directory and run the following command. Instructions in the Dockerfile are executed.

Please observe that there is dot (.) at the end of the command. Docker image is successfully built.

6. Check the docker image

To display available docker images, run the following command.

Install Kafka Docker Command

Run Docker Java Example

Run the following command to run the java-application Docker image in a container.

The Java Application has run, and the print statement could be seen in the console.

Save Docker Image to a tar file

Save the Docker Image file to a tar file, so that the image file could be copied to other machines through disk storage devices like pen-drive, etc.

Run the following command to save Docker image as a tar file.

Saving might take few seconds. Wait for the command to complete.

Copy and Run the Docker Image file in another machine

You may copy the Docker image tar file to another computer.

Run the following command to load the Docker image into the Docker.

Replace /home/arjun/workspace/java-application.tar with your file location.

Kafka

You may run the image using the same command we used to run the image file after building.

Install Kafka Docker Commands

Conclusion

Install Kafka Docker Centos

In this Docker Tutorial – Docker Java Example, we have learnt to build a Docker Image with Java Application and also how to save the image to a file and transfer it to other computers or servers.