i deployed jenkins as docker container. Created a job to build and push docker image as maven project. But when tried to build the it ends up in error.
[INFO] --- maven-antrun-plugin:1.3:run (build-service-docker-image) # infyDockerImageTomcat8 ---
[INFO] Executing tasks
[echo] Running [docker build -t hi2vaisakh/infy-poc-tomcat8:v1.0 .]
[exec] /bin/sh: 1: docker: not found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
You have to mount the docker sockets from your host machine into your jenkins container if you want to use the docker commands in Jenkins. Something like this should work:
docker run -d \
-u root \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker:ro \
-v /lib64/libdevmapper.so.1.02:/usr/lib/x86_64-linux-gnu/libdevmapper.so.1.02 \
-v /lib64/libudev.so.0:/usr/lib/x86_64-linux-gnu/libudev.so.0 \
-p 8080:8080 \
--name jenkins \
--privileged=true -t -i \
jenkins
Related
This is my buildspec.yml:
phases:
install:
runtime-versions:
java: corretto11
pre_build:
commands:
- COMMIT_ID_SHORT=`echo "${CODEBUILD_RESOLVED_SOURCE_VERSION}" | cut -c1-8`
- TAG=`echo "${MAJOR}.${MINOR}.${COMMIT_ID_SHORT}"`
- aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin ${ECR_URL}
- export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain cloud-infra-packages --domain-owner 715371302281 --query authorizationToken --output text`
build:
commands:
- gradle clean build
- docker build -t ${APP}:${TAG} -f Dockerfile
- docker tag ${APP}:${TAG} ${ECR_URL}/${ECR_URL}:${TAG}
But I got a error message:
the gradle version is not supported, and I found the gradle version of codebuild standard image is 5.6.0, so how to modify the gradle version when build the project in AWS codebuild.
already fixed the problem, we should use ./graldew to build the project, not gralde.
Created local registry:
reg_name='kind-registry'
reg_port='5000'
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
if [ "${running}" != 'true' ]; then
docker run \
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
registry:2
fi
Created a builder:
docker buildx create --name my-builder --platform linux/arm64
docker buildx build --builder my-builder --tag localhost:5000/micro --platform linux/arm64 --push -f ./docker/Dockerfile .
Error:
> exporting to image:
------
error: failed to solve: failed to do request: Head "http://localhost:5000/v2/micro/m1/blobs/sha256:cb74f5ebe9cfa5414583bf566983f0ac366f4f6d0b69df2bad27005295378933": dial tcp 127.0.0.1:5000: connect: connection refused
I am trying a maven pipeline in jenkins on my windows machine. I am running the jenkins container through below command:
docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins
My Jenkinsfile is as follows:
pipeline {
agent {
docker {
image 'maven:3.8.1-adoptopenjdk-11'
args '-v /root/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B -DskipTests clean package'
}
}
}
}
while building the pipeline i am getting the below error:
+ docker inspect -f . maven:3.8.1-adoptopenjdk-11
/var/jenkins_home/workspace/simple-java-maven-app#tmp/durable-2227453d/script.sh: 1:
/var/jenkins_home/workspace/simple-java-maven-app#tmp/durable-2227453d/script.sh: docker: not found
[Pipeline] isUnix
[Pipeline] sh
+ docker pull maven:3.8.1-adoptopenjdk-11
/var/jenkins_home/workspace/simple-java-maven-app#tmp/durable-f8b58578/script.sh: 1:
/var/jenkins_home/workspace/simple-java-maven-app#tmp/durable-f8b58578/script.sh: docker: not found
[Pipeline] }
Docker desktop is already installed on my machine so not able to get Why I am getting "docker:not found" error.
Can anyone please point out if I am missing something.
Thanks,
If you run the command such as :
docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins
you don't provide a way to jenkins to access to the docker installed on your host.
To allow that, mount the docker socket as a volume inside your docker run command.
On windows (according to Bind to docker socket on Windows) :
-v //var/run/docker.sock:/var/run/docker.sock
And on linux :
-v /var/run/docker.sock:/var/run/docker.sock
This is how I run GitLab with Docker:
Step 1. Launch a postgresql container
docker run --name gitlab-postgresql -d \
--env 'DB_NAME=gitlabhq_production' \
--env 'DB_USER=gitlab' --env 'DB_PASS=password' \
--volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \
sameersbn/postgresql:9.4-12
Step 2. Launch a redis container
docker run --name gitlab-redis -d \
--volume /srv/docker/gitlab/redis:/var/lib/redis \
sameersbn/redis:latest
Step 3. Launch the gitlab container
docker run --name gitlab -d \
--link gitlab-postgresql:postgresql --link gitlab-redis:redisio \
--publish 10022:22 --publish 10080:80 \
--env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \
--env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \
--volume /srv/docker/gitlab/gitlab:/home/git/data \
sameersbn/gitlab:8.4.2
However, when I restart or shutdown the computer, all previous data is gone.
Please help me, I am new to Docker and GitLab in Docker.
Your approach seems correct and I do not see why the volumes wouldn't persist your data. When you've restarted your computer, you can try to start the stopped containers using these commands:
docker start gitlab-postgresql
docker start gitlab-redis
docker start gitlab
By the way, I'd recommend using this docker-compose.yml file to setup your gitlab environent. Just download the file and run docker-compose up -d.
When using the file circle.yml file to build a docker image I'm trying to pass an environment variable $CIRCLE_PROJECT_USERNAME so that the file is less project specific. Unfortunately Docker build with the tag argument -t fails with:
docker build -t CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH . returned exit code 1
repository name component must match "[a-z0-9]+(?:[._-][a-z0-9]+)*" Action failed: docker build -t CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH .
Circle.yml file:
machine:
environment:
services:
- docker
dependencies:
override:
- docker info
- docker build -t CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH .
test:
override:
- docker run -d $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH
deployment:
hub:
branch: master
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASSWORD
- docker push $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH
deployment:
hub:
branch: develop
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASSWORD
- docker push $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH
Should work, check if the env are actually set and only contain allowed characters:
[a-z0-9]+(?:[._-][a-z0-9]+)*
Edit:
docker build -t CIRCLE_PROJECT_USERNAME ...
Maybe just missing a $ here? ;)