I have a docker-compose.yml file that defines all the services I need. The important parts are the following:
services:
backend-api:
build: .
jenkins:
build: ./jenkins
volumes:
- jenkins_data:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
The backend-api is a simple Java application built with gradle and the jenkins service is the standard jenkins image with docker installed into it.
Dockerfile of backend-api:
FROM gradle:jdk8 as builder
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle build
FROM openjdk:8-jre-slim
EXPOSE 8080
COPY --from=builder /home/gradle/src/backend/build/distributions/backend.tar /app/
WORKDIR /app
RUN tar -xvf backend.tar
WORKDIR /app/backend
CMD bin/backend
I want to rebuild and restart the backend-api
service from the jenkins
container. I read about his a lot and looked at the CloudBees
docker plugins for jenkins
but I cant figure out how to restart and rebuild the container on the host from inside the jenkins container.
Is it possible to achieve this somehow or is my whole approach to this wrong?
You need to configure properly the docker client inside jenkins docker container. Here is the Dockerfile or the entire post
After that you can use -H docker parameter to exec any command in remote dockers. Foe example I use this to see my remote logs from another another machine:
docker -H 10.10.10.66:2375 logs --tail 500 my-app
Note: You must to enable docker rest api before!
The common, easy, manual and proven way to work with C.I and docker is:
Note:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.