I'm using a jenkins container, i ran this container using docker-compose
Here is my docker-compose file:
version: '3.3'
services:
jenkins-service:
build:
context: ./
image: docker/jenkins-local
ports:
- 8080:8080
- 5000:5000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- jenkins_data_prod:/var/jenkins_home
- jenkins_tmp_data_prod:/tmp
volumes:
jenkins_data_prod:
jenkins_tmp_data_prod:
and here is my dockerfile
FROM jenkins/jenkins:lts
# Installation of docker
USER root
RUN curl -sSL https://get.docker.com/ | sh
# Adding user jenkins in groupe "docker"
RUN usermod -aG docker jenkins
# Installation of docker-compose
RUN curl -L https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
RUN chmod +x /usr/local/bin/docker-compose
#USER jenkins
After that i ran jenkins using docker-compose up --build command
i first noticed that my docker is mounting volumes "jenkins_jenkins_data_prod", and "jenkins_jenkins_tmp_data_prod" as name, while i was writing only "jenkins_data_prod" and "jenkins_tmp_data_prod" on my docker-compose.yml, so i modified my file and wrote volumes names as "data_prod" and "tmp_data_prod"
like this :
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- data_prod:/var/jenkins_home
- tmp_data_prod:/tmp
volumes:
data_prod:
tmp_data_prod:
i Found volumes mounted in "/var/lib/docker/volumes/jenkins_data_prod/_data" as "jenkins_data_prod" and "jenkins_tmp_data_prod" when i used to inspect the mountpoint using this command :
'docker volume inspect jenkins_data_prod'
Result command :
terminal :
{
"CreatedAt": "2021-06-15T23:33:41Z",
"Driver": "local",
"Labels": {
"com.docker.compose.project": "jenkins",
"com.docker.compose.version": "1.29.1",
"com.docker.compose.volume": "data_prod"
},
"Mountpoint": "/var/lib/docker/volumes/jenkins_data_prod/_data",
"Name": "jenkins_data_prod",
"Options": null,
"Scope": "local"
}
So after that i'm running a Jenkins pipline to build a personnal project on gitlab, it's using "/var/jenkins_home" as workspace
i have a docker-compose.yml file using bindmount volumes
My docker-compose to run
version: '3.3'
services:
netcore:
image: mcr.microsoft.com/dotnet/sdk:3.1
volumes:
- ../../projet-api/:/sources
- ${NUGET_HOME}/.nuget/:/root/.nuget
- ../build/netcore/application:/application
working_dir: /sources
command: dotnet publish -o /application -c Debug --self-contained false /p:Version=${VERSION}
when i run the image on "/var/jenkins_home" workspace i use to have error
+ docker-compose run --rm netcore
Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
so "/var/jenkins_home" was empty and my docker-compose only created folders with the name of "/projet-api" and "/build/netcore/application" i used to see where is the workspace containing the project i found it in "\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\jenkins_data_prod_data\workspace"
i looked arround docs and found that "\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes" was mapped to "/var/lib/docker/volumes/"
so i decided to try to run the image using environnement variables
version: '3.3'
services:
netcore:
image: mcr.microsoft.com/dotnet/sdk:3.1
volumes:
- ${PWD_docker}/../../projet-api/:/sources
- ${NUGET_HOME}/.nuget/:/root/.nuget
- ${PWD_docker}/../build/netcore/application:/application
working_dir: /sources
command: dotnet publish -o /application -c Debug --self-contained false /p:Version=${VERSION}
My running part of jenkinsfile
node {
//*********************************
// getting code
//*********************************
stage ('SCM'){
checkout scm
}
//*********************************
// docker images
//*********************************
stage('RUNNING NETCORE') {
dir ('project-docker/compile'){
def containerPWD = pwd() // printing /var/jenkins_home/....
def pwdval = "/var/lib/docker/volumes/jenkins_data_prod/_data"
def dockerHostPWD = containerPWD.replace("/var/jenkins_home", pwdval)// /var/lib/docker/volumes/jenkins_data_prod/_data
def props = readProperties file: '.env'
VERSION = props.VERSION
withEnv(["NUGET_HOME=${dockerHostPWD}","VERSION=${VERSION}","PWD_docker=${dockerHostPWD}"]) {
sh """
docker-compose run --rm netcore
"""
}
}
}
.
// rest of the code .
.
still same error of MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
Questions
1/ running my docker-compose using those paths only creating folders, at the last one i put it was in "\wsl$\Ubuntu\var\lib\docker\volumes" so looks like jenkins doesnt access to "\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes" which is the workspace containing the project, using path "/var/lib/docker/volumes" anyone can help me out finding how to access to volumes ? Maybe "/var/lib/docker/volumes" is not really mapping to "\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes" ? but for "\wsl$\Ubuntu\var\lib\docker\volumes" ?
( without having to make symbolic link,or bindmounting my host "/var/jenkins_home" to jenkins "/var/jenkins_home" in the docker-compose that run jenkins.)
2/ My second question is why i'm getting "jenkins_" prefixed to my volumes, we can see on labels "com.docker.compose.volume": "data_prod" and we see at the name "Name": "jenkins_data_prod" and why the label volume is "data_prod" and volume name isnt