Skip to content

Commit 7129d50

Browse files
committed
Dockerfile and docker-compose.yml
1 parent 2d99bbb commit 7129d50

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ services:
2828
build:
2929
context: polling-app-client # Use an image built from the specified dockerfile in the `polling-app-client` directory.
3030
dockerfile: Dockerfile
31+
args:
32+
REACT_APP_API_BASE_URL: http://127.0.0.1:8080/api
3133
ports:
3234
- "9090:80" # Forward the exposed port 80 on the container to port 80 on the host machine
3335
restart: always

polling-app-client/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ RUN npm install
1616
# Copy the main application
1717
COPY . ./
1818

19+
# Arguments
20+
ARG REACT_APP_API_BASE_URL
21+
ENV REACT_APP_API_BASE_URL=${REACT_APP_API_BASE_URL}
22+
1923
# Build the application
2024
RUN npm run build
2125

polling-app-server/Dockerfile

+30-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1-
# Start with a base image containing Java runtime
2-
FROM openjdk:8-jdk-alpine
1+
#### Stage 1: Build the application
2+
FROM openjdk:8-jdk-alpine as build
33

4-
# Add Maintainer Info
5-
LABEL maintainer="callicoder@gmail.com"
4+
# Set the current working directory inside the image
5+
WORKDIR /app
66

7-
# Add a volume pointing to /tmp
8-
VOLUME /tmp
7+
# Copy maven executable to the image
8+
COPY mvnw .
9+
COPY .mvn .mvn
910

10-
# Make port 8080 available to the world outside this container
11-
EXPOSE 8080
11+
# Copy the pom.xml file
12+
COPY pom.xml .
1213

13-
# The application's jar file
14-
ARG JAR_FILE=target/polls-0.0.1-SNAPSHOT.jar
14+
# Build all the dependencies in preparation to go offline.
15+
# This is a separate step so the dependencies will be cached unless
16+
# the pom.xml file has changed.
17+
RUN ./mvnw dependency:go-offline -B
1518

16-
# Add the application's jar to the container
17-
ADD ${JAR_FILE} app.jar
19+
# Copy the project source
20+
COPY src src
1821

19-
# Run the jar file
20-
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
22+
# Package the application
23+
RUN ./mvnw package -DskipTests
24+
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)
25+
26+
#### Stage 2: A minimal docker image with command to run the app
27+
FROM openjdk:8-jre-alpine
28+
29+
ARG DEPENDENCY=/app/target/dependency
30+
31+
# Copy project dependencies from the build stage
32+
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
33+
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
34+
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
35+
36+
ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.polls.PollsApplication"]

0 commit comments

Comments
 (0)