dockerdockerfileauto-build

Multi image with Docker automated build


I link my hub.docker.com account with bitbucket.org for automated build. In core folder of my repository exist Dockerfile, which is inside 2 image building steps. If I build images based same Dockerfile in local (i mean in Windows), I get 2 different images. But if I will use hub.docker.com for building, only last image is saved and tagged as "latest".

Dockerfile:

#-------------First image ----------
FROM nginx 

#-------Adding html files
RUN mkdir /usr/share/nginx/s1
COPY content/s1 /usr/share/nginx/s1
RUN mkdir /usr/share/nginx/s2
COPY content/s2 /usr/share/nginx/s2

# ----------Adding conf file
RUN rm -v /etc/nginx/nginx.conf
COPY conf/nginx.conf /etc/nginx/nginx.conf

RUN service nginx start


# ------Second image -----------------
# Start with a base image containing Java runtime
FROM openjdk:8-jdk-alpine

# Add a volume pointing to /tmp
VOLUME /tmp

# Make port 8080 available to the world outside this container
EXPOSE 8080

# The application's jar file
ARG JAR_FILE=jar/testbootstap-0.0.1-SNAPSHOT.jar

# Add the application's jar to the container
ADD ${JAR_FILE} test.jar

# Run the jar file 
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/test.jar"]

Anybody did this before or its not possible?

PS: There only one private repository for free use, may be this is main reason.


Solution

  • I found some walk-around for this problem.

    1. I separate docker file to two file.

           1.docker for ngix  
           2.docker for java app
      
    2. In build settings set this two files as dockerfile and tag with different tags. enter image description here

    3. After building you have one image but versions is define as image name. For example you can use

       for nginx server youraccount/test:nginx   
       for app image youraccount/test:java
      

    enter image description here

    enter image description here I hope this will be no problem in future processes.