Git Product home page Git Product logo

java-maven-docker-example's Introduction

java-maven-docker-example

This project is an example of how to integrate Maven based Java application with Docker, using Spotify's docker-maven-plugin.

cli

Build an image by running this command.

$ cd java-maven-docker-example/cli
$ mvn clean package

Run image on container.

$ docker run cli
Hello world!

You can also specify command line argument.

$ docker run cli there
Hello there!

http-server

Building an image is done by same command above.

$ cd java-maven-docker-example/http-server
$ mvn clean package

The difference between cli and http server is actually http server uses a custom Dockerfile stored under java-maven-docker-example/http-server/docker directory while cli sets base image and entry point directly in the pom. For http server, we need to expose the listen port to Docker by giving an EXPOSE instruction which is not yet supported in docker-maven-plugin.

To run the server on the container, run this command.

$ docker run -d -P http-server

Now you see the list of containers by the following command.

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                     NAMES
17178a5067a2        http-server         "java -cp /http-serve"   About a minute ago   Up About a minute   0.0.0.0:32769->9999/tcp   compassionate_heisenberg

Make sure http server is listening on localhost:32769 (Docker binds port automatically in this case).

$ curl localhost:32769
Hello world!

java-maven-docker-example's People

Contributors

tatsuya avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.