I am using a docker-compose file for two services. One for React App and another for Nginx server. I am using Jenkins to build periodically (15 minutes period). In jenkins's build section I execute the command docker-compose up --build
. But the problem is whenever jenkins start to build it takes unlimited time to finish although both of the containers are already started after a few minutes of starting to build. Due to not finished the first build another build comes into the queue as pending.
Now my question is how to finish the build process when the containers are started.
docker-compose
version: "3"
services:
react-app:
container_name: frontend_app
build:
context: .
dockerfile: ./Dockerfile
image: frontend_app:dev
tty: true
volumes:
- my_host_vol:/app/build/
networks:
- frontend_network
nginx-server:
image: nginx_for_frontend:dev
container_name: nginx_for_frontend
tty: true
build:
context: ./nginx
dockerfile: Dockerfile
# restart: on-failure
volumes:
- .:/my_frontend_server
- my_host_vol:/var/www/html/
ports:
- 80:80
depends_on:
- react-app
networks:
- server_network
networks:
frontend_network:
driver: bridge
server_network:
driver: bridge
volumes:
my_host_vol:
Dockerfile For React app
FROM node:10.16.3
RUN mkdir /app
WORKDIR /app
COPY . /app
ENV PATH /app/node_modules/.bin:$PATH
RUN npm install --silent
RUN npm install react-scripts@3.0.1 -g --silent
RUN npm run-script build
Dockerfile for nginx
FROM nginx:1.16.1-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY /prod.conf /etc/nginx/conf.d
Screenshot of Jenkins console of build process
Finally I have found the solution
If I run my compose file in detach mode (-d) then it is exited from the console when all the services started to run and keeps those services running in background.
docker-compose up --build -d // <------ Here I added '-d'
Before I ran the command without detach mode (docker-compose up --build
) that's why it was running in jenkins console. And for that jenkins build process took infinity time to complete the complete the build.
That's it !