Jenkins docker setup - jenkins

I am using Jenkins to make build of project, but now my client wants to make builds inside of a Docker image. i have installed docker on server and its running on 172.0.0.1:PORT. I have installed Docker plugin and assigned this TCP URL to Docker URL. I have also created an image with the name jenkins-1
In configure project I use Build environment Build with Docker Container and provide image name. and then in Build in put Execute Shell and then Build it
But it gives the Error:
Pull Docker image jenkins-1 from repository ...`
$ docker pull jenkins-1`
Failed to pull Docker image jenkins-1`
FATAL: Failed to pull Docker image jenkins-1`
java.io.IOException: Failed to pull Docker image jenkins-1``
at com.cloudbees.jenkins.plugins.docker_build_env.PullDockerImageSelector.prepare DockerImage(PullDockerImageSelector.java:34)`
at com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper.setUp(DockerB`uildWrapper.java:169)`
at hudson.model.Build$BuildExecution.doRun(Build.java:156)`
at `hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)`
at hudson.model.Run.execute(Run.java:1720)`
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)`
at hudson.model.ResourceController.execute(ResourceController.java:98)`
at hudson.model.Executor.run(Executor.java:404)`
Finished: FAILURE`

I just have run into the same issue. There is a 'Verbose' check-box in the configuration of build environment after selecting 'Advanced...' link to expand on the error details:
CloudBees plug-in Verbose option
In my case I ran out of space downloading the build Docker images. Expanding ec2 volume has resolved the issue.
But there is an ongoing trouble with space as docker does not auto cleans images and I have ended up adding a manual cleanup step into the build:
docker volume ls -qf dangling=true | xargs -r docker volume rm
Complete build script:
https://bitbucket.org/vk-smith/dotnetcore-api/src/master/ci-build.sh?fileviewer=file-view-default

Related

Gcloud and docker confusion

I am very lost on the steps with gcloud verse docker. I have some gradle code that built a docker image and I see it in images like so
(base) Deans-MacBook-Pro:stockstuff-all dean$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gcr.io/prod-stock-bot/stockstuff latest b041e2925ee5 27 minutes ago 254MB
I am unclear if I need to run docker push or not or if I can go strait to gcloud run deploy so I try a docker push like so
(base) Deans-MacBook-Pro:stockstuff-all dean$ docker push gcr.io/prod-stockstuff-bot/stockstuff
Using default tag: latest
The push refers to repository [gcr.io/prod-stockstuff-bot/stockstuff]
An image does not exist locally with the tag: gcr.io/prod-stockstuff-bot/stockstuff
I have no idea why it says the image doesn't exist locally when I keep listing the image. I move on to just trying gcloud run deploy like so
(base) Deans-MacBook-Pro:stockstuff-all dean$ gcloud run deploy stockstuff --project prod-stock-bot --region us-west1 --image gcr.io/prod-stockstuff-bot/stockstuff --platform managed
Deploying container to Cloud Run service [stockstuff] in project [prod-stock-bot] region [us-west1]
X Deploying... Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.
X Creating Revision... Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.
. Routing traffic...
Deployment failed
ERROR: (gcloud.run.deploy) Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.
I am doing this all as a playground project and can't seem to even get a cloud run deploy up and running.
I tried the spring example but that didn't even create a docker image and it failed anyways with
ERROR: (gcloud.run.deploy) Missing required argument [--image]: Requires a container image to deploy (e.g. `gcr.io/cloudrun/hello:latest`) if no build source is provided.
This error occurs when an image is not tagged locally/correctly. Steps you can try on your side.
Create image locally with name stockstuff (do not prefix it with gcr and project name while creating).
Tag image with gcr repo detail
$ docker tag stockstuff:latest gcr.io/prod-stockstuff-bot/stockstuff:latest
Check if your image is available in GCR (must see your image here, before deploying on cloudrun).
$ gcloud container images list --repository gcr.io/prod-stockstuff-bot
If you can see your image in list, next you can try to deploy gcloud run with below command (as yours).
gcloud run deploy stockstuff --project prod-stock-bot --region us-west1 --image gcr.io/prod-stockstuff-bot/stockstuff --platform managed
There are 3 contexts that you need to be aware.
Your local station, with your own docker.
The cloud based Google Container Registry: https://console.cloud.google.com/gcr/
Cloud Run product from GCP
So the steps would be:
Build your container either locally or using Cloud Build
Push the container to the GCR registry,
if you built locally
docker tag busybox gcr.io/my-project/busybox
docker push gcr.io/my-project/busybox
Deploy to Cloud Run a container from Google Cloud Repository.
I don't see this image gcr.io/prod-stockstuff-bot/stockstuff when you list images in the local system. You can create a new image by tagging that image with this image gcr.io/prod-stock-bot/stockstuff and re-run the gcloud run command.
for the context I am using Flask (python)
I solved this by
update gcloud-sdk to the latest version
gcloud components update
add .dockerignore, I'm guessing because of the python cache
Dockerfile
README.md
*.pyc
*.pyo
*.pyd
__pycache__
.pytest_cache
expose the port to env $PORT
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 app:app

Unknown Manifest after Docker pull in build pipeline when committing to GitLab

After pushing a commit to GitLab the build pipeline starts to check the new commit. Build and Test stage run successfully. But the Deploy stage stops with the following error:
Running with gitlab-runner 12.3.0 (a8a019e0)
on gitlab-runner2 QNyj_HGG
Using Docker executor with image nexus.XXX.com/YYY/ZZZ-engines ...
Authenticating with credentials from /root/.docker/config.json
Pulling docker image nexus.XXX.com/YYY/ZZZ-engines ...
ERROR: Job failed: Error response from daemon: manifest for
nexus.XXX.com/YYY/ZZZ-engines:latest not found: manifest unknown: manifest unknown (executor_docker.go:188:0s)
What could be the reason behind that?
I had the same problem, I solved it by rebuilding and republishing the docker image that the GitLab CI file was referencing and then re-run the pipeline again and it worked.
There is no latest tag for that specific docker image. Most likely you're building using a specific tag, e.g v1.0:
docker build -t nexus.XXX.com/YYY/ZZZ-engines:v1.0 .
then using that image without a tag in your .gitlab-ci.yml:
image: nexus.XXX.com/YYY/ZZZ-engines
# OR
build-job:
stage: build
image: nexus.XXX.com/YYY/ZZZ-engines
...
To fix, either specify a tag in you ci file, or tag the image with latest when building:
docker build -t nexus.XXX.com/YYY/ZZZ-engines:v1.0 -t nexus.XXX.com/YYY/ZZZ-engines:latest .
The gitlab docker template has a nice example of how to automatically tag a build as latest on the default branch: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Docker.gitlab-ci.yml

docker image in gitlab CI used for create docker image

I want to build docker with "ready to run" application in docker CI, so to do that I have created in .gitlab-ci.yml this code:
rebuild base docker:
stage: prepear
image: docker
script:
- docker build -t base_django environment
I want to use the official docker image to do it (image: docker), of course in directory environment I have placed Dockerfile. Unfortunately job faild on:
Running with gitlab-runner 11.8.0 (4745a6f3)
on docker-auto-scale 72989761
Using Docker executor with image docker ...
Pulling docker image docker ...
Using docker image sha256:639de9917ae1f2e4a586893c9a6ea3f21fd774bc4037184ecac35f3153a293b5 for docker ...
Running on runner-72989761-project-9841176-concurrent-0 via runner-72989761-srm-1552402128-c63119b1...
Cloning repository...
Cloning into '/builds/*****/*****'...
Checking out a804a12f as master...
Skipping Git submodules setup
$ docker build -t base_django environment
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
ERROR: Job failed: exit code 1
You need a specific configuration to run docker in docker with Gitlab CI. You can find more information right here : https://docs.gitlab.com/ee/ci/docker/using_docker_build.html

Failure - Authentication is required to pull public docker images from Dockerhub registry

I am using Jenkins Custom Build Environment Plugin (1.6.5) to build images from a Dockerfile inside the slave container checked in along with the source code.
Slaves running on Docker version 1.9.1, build ab77bde/1.9.1
My Dockerfile is as below which is able to pull from official ubuntu image but fails to pull from official node.js image -
FROM node:boron
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
On Jenkins job execution I get below failure -
$ docker build --file /data/name-jenkins/workspace/TestJobs/BuildFromSCM/Dockerfile /data/name-jenkins/workspace/TestJobs/BuildFromSCM
Sending build context to Docker daemon 149.5 kB
Sending build context to Docker daemon 149.5 kB
Step 1 : FROM node:boron
Trying to pull repository registry.access.redhat.com/node ... failed
Trying to pull repository docker.io/library/node ... failed
Authentication is required.
FATAL: Failed to build docker image from project Dockerfile
java.lang.RuntimeException: Failed to build docker image from project Dockerfile
at com.cloudbees.jenkins.plugins.docker_build_env.Docker.buildImage(Docker.java:134)
at com.cloudbees.jenkins.plugins.docker_build_env.DockerfileImageSelector.prepareDockerImage(DockerfileImageSelector.java:46)
at com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper.setUp(DockerBuildWrapper.java:169)
at hudson.model.Build$BuildExecution.doRun(Build.java:156)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1741)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Finished: FAILURE
I am able to build the Docker image on my local machine though. I confirmed that the Jenkins slave user has sudo permissions.
I found an issue in .docker/config.json on my slave machine where I accidentally set my dockerhub credentials which caused in failure in pulling public images with a generic user I was using to build Jenkins job.
{
"ServerURL": "https://index.docker.io/v1",
"Username": "myusername",
"Secret": "passw0rd1"
}
You may need a certificate of the docker-hub, which is a ca.crt file put in:
/etc/docker/certs.d/

how to list Docker images with Vagrant and Kubernetes

I try to Install Stratos with Kubernetes in a Testing Environment to build Stratos.I downloading the Kubernetes binaries and provisioned a Docker registry to VAGRANT_KUBERNETES_SETUP folder (in 2.c. i in page).But it gives 3 Failed Units(docker.service,setup-network-environment.service and docker.socket) When I Log into the master node.So I can't view Docker images by using 'docker images' command.when I view docker images it give this error-"FATA[0000] Cannot connect to the Docker daemon. Is 'docker -d' running on this host?" how can i fixed this problem?do i need to install in different way to work with vagrant?
Did you do a sudo -s on the node ? You have to be an admin to connect to the docker daemon and do queries using docker command line client.

Resources