Search code examples
javamavenspring-bootdockerspring-cloud-config

Create docker file for spring cloud config server


I am trying to build docker image for my config server. These are the steps which I have followed:

  • Open https://start.spring.io/ and added config-server as a dependancies. then downloaded the project.
  • Added @EnableConfigServer annotation in demo\src\main\java\com\example\demo\DemoApplication.java
  • Added below code in demo\src\main\resources\application.properties

server.port=8888 spring.cloud.config.server.git.uri=https://github.com/mygitusername/configserverdata.git

When I started config server using command mvn spring-boot:run on local, It's working fine.

Now I want to create docker image for my config server. for this I get this docker file from here.

FROM maven:alpine
MAINTAINER hyness <hyness@freshlegacycode.org>

EXPOSE 8888
COPY . /Demo/
WORKDIR /Demo/
RUN mvn package
VOLUME /config
WORKDIR /
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar",\
            "/Demo/target/Demo.jar",\
            "--server.port=8888",\
            "--spring.config.name=application"]

When I execute docker build -t spring-cloud-config-server . it says BUILD Failure with this reason

The goal you specified requires a project to execute but there is no POM in this directory (/demo). Please verify you invoked Maven from the correct directory.

Please help me to create correct docker file for my config server.

It might be a silly question, But I need to specify mvn spring-boot:run in Dockerfile as well.

I've just started learning docker.


Solution

  • I have just built the application and it works fine with this Dockerfile and dirs layout (have alook at "COPY ./demo /demo/") :

    FROM maven:alpine
    MAINTAINER hyness <hyness@freshlegacycode.org>
    
    EXPOSE 8888
    COPY ./demo /demo/
    WORKDIR /demo/
    RUN mvn package
    VOLUME /config
    WORKDIR /
    ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar",\
                "/demo/target/demo.jar",\
                "--server.port=8888",\
                "--spring.config.name=application"]
    $ tree
    .
    ├── demo
    │   ├── pom.xml
    │   └── src
    │       └── main
    │           ├── java
    │           │   └── com
    │           │       └── example
    │           │           └── demo
    │           │               └── DemoApplication.java
    │           └── resources
    │               └── application.properties
    └── Dockerfile