Search code examples
javamavendockerdocker-build

Docker image of Java project


I am trying make a docker image of a java project. I first created a directory and in that I created a docker.txt file. The files contains this

FROM java:8 

# Install maven
RUN apt-get update  
RUN apt-get install -y maven

WORKDIR /home/mmt/CouchBaseClient/CB-RestAPI/CouchBaseThinClient

# Prepare by downloading dependencies
ADD pom.xml /home/mmt/CouchBaseClient/CB-RestAPI/CouchBaseThinClient/pom.xml  
RUN ["mvn", "dependency:resolve"]  
RUN ["mvn", "verify"]

# Adding source, compile and package into a fat jar
ADD src /home/mmt/CouchBaseClient/CB-RestAPI/CouchBaseThinClient/src  
RUN ["mvn", "package"]

EXPOSE 4567  
CMD ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "target/sparkexample-jar-with-dependencies.jar"]

and then I run in terminal the following command

docker build -t API .

I get the following error

invalid value "API" for flag -t: Error parsing reference: "API" is not a valid repository/tag
See 'docker build --help'.

Solution

  • Docker is complaining about "API" in the sense that it's not allowed to have a tag name with one or more character in uppercase:

    $ docker build -t FOO .
    repository name component must match "[a-z0-9](?:-*[a-z0-9])*(?:[._][a-z0-9](?:-*[a-z0-9])*)*"
    

    Usually "recipes" to build Docker images are written in a file named Dockerfile, anyway you can continue to use docker.txt using the -f option:

    docker build -f docker.txt -t api .