I am following the tutorial located here. I am able to get a self hosted agent running in a Docker container. After the agent is running, I am able to run jobs on it in a pipeline only while the container is running. I would like to keep this docker container build agent running as a service, so I don't have to start it up for each time I am executing a pipeline. Any advice on how to configure a docker container build agent to keep running continuously would be helpful.
I am able to run jobs on it in a pipeline only while the container is
running.
Agent in Docker should be 'run as a service' by default, you need to make sure the container is running, otherwise, the agent will not run.
Related
Application was using docker CLI to build and then push an image to azure container registry. Used to work fine on Kubernetes using a python module and docker.sock. But since cluster upgraded docker daemon is gone. Guessing the K8 backend no longer uses docker or has it installled. Also, since docker is going away in kubernetes (i think it said 1.24 I want to get away from counting on docker for the build.
So the application when working was python application running in a docker container. It would take the dockerfile and build it and push it to azure container registry. There are files that get pushed into the image via the dockerfile and they all exist in the same directory as the dockerfile.
Anyone know of different methods to achieve this?
I've been looking at Azure ACR Tasks but I'm not really sure how all the files get copied over to a task and have not been able to find any examples.
I can confirm that running an Azure ACR Task (Multi-Task or Quick Task) will copy the files over when the command is executed. We're using Azure ACR Quick Tasks to achieve something similar. If you're just trying to do the equivalent of docker build and docker push, Quick Tasks should work fine for you too.
For simplicity I'm gonna list the example for a Quick Task because that's what I've used mostly. Try the following steps from your local machine to see how it works. Same steps should also work from any other environment provided the machine is authenticated properly.
First make sure you are in the Dockerfile directory and then:
Authenticate to the Azure CLI using az login
Authenticate to your ACR using az acr login --name myacr.
Replace the values accordingly and run az acr build --registry myacr -g myacr_rg --image myacr.azurecr.io/myimage:v1.0 .
Your terminal should already show all of the steps that the Dockerfile is executing. Alternatively you can head over to your ACR and look under services>tasks>runs. You should see every line of the Docker build task appear there.
Note: If you're running this task in an automated fashion and also require access to internal/private resources during the image build, you should consider creating a Dedicated Agent Pool and deploying it in your VNET/SNET, instead of using the shared/public Agent Pools.
In my case, I'm using terraform to run the az acr build command and you can see the Dockerfile executes the COPY commands without any issues.
I need help in creating the container through Jenkins job.
Let me know the steps to be followed: I have already created 3 jobs in Jenkins, and I want to create httpd container through the jobs created.
Should I install any plugins or write any script ?
Assuling we are not talking about Jenkins in docker, or Jenkins agents in Docker, you need to create your http container manually first, without Jenkins.
That means:
validate your SSH access to the remote server
Check it has Docker installed
execute docker commands to run an http container, s described in Docker httpd
Once that is working, you can replicate the process in a Jenkins Job, provided your remote server (the one with Docker, where you want to run your httpd container) is declared as agent to the main Jenkins controller.
I cannot manage to deploy 'ubuntu' to Azure Container instance without it becoming "Terminated" right after the deployment. I tried setting the command to ["/bin/bash"], however, it doesn't stop the container from terminating.
It's a common issue you can see. The docker image ubuntu just provides the base container, but no application runs in it to make the Container Instance in the running state. So you need to add the command in the command line to make the container instance in the running state. For example, add the command tail -f /dev/null.
When you do it in the portal, it should look like this:
It just keeps the container in the running state and does not output anything. So there are no logs output.
With a self-hosted agent, I m getting following error at the end of VSTS build pipeline.
2018-10-04T12:11:10.3334402Z ##[error]unauthorized: authentication required
2018-10-04T12:11:10.3447576Z ##[error]/snap/bin/docker failed with return code: 1
The point is I want to push Docker image to Azure Container Registry, using Docker extension.
When I perform exactly same pipeline on my Ubuntu machine, where agent builds, just with Docker commands, push succeeds. Build succeeds and repository is pushed to cloud.
How can I authenticate Docker for my build agent, to be able to push?
I am following the official tutorial from Jenkins website. I have a blueocean Docker container that is running the pipeline in the Jenkinsfile as per tutorial:
pipeline {
agent {
docker {
image 'node:6-alpine'
args '-p 3000:3000'
}
}
stages {
stage('Build') {
steps {
sh 'npm install'
}
}
}
}
The problem is that the pipeline fails when it tries to pull the Docker image:
[ode-js-react-npm-app_master-6PEWX3VWDA4SAdDMJA4YKJCZSABJSAQCSGVYMKHINXGDDJLA] Running shell script
+ docker pull node:6-alpine
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
script returned exit code 1
After some troubleshooting, I realized that this is failing because Jenkins is trying to pull the Docker container itself, rather than the host. This is not what I want, and the documentation in fact states:
This image parameter (of the agent section’s docker parameter) downloads the node:6-alpine Docker image (if it’s not already available on your machine) and runs this image as a separate container. This means that:
You’ll have separate Jenkins and Node containers running locally in Docker.
The Node container becomes the agent that Jenkins uses to run your Pipeline project. However, this container is short-lived - its lifespan is only that of the duration of your Pipeline’s execution.
Can someone explain what I am doing wrong and why the Node.js Docker image is tried being pulled inside Jenkins instead of the local machine? I want to have a separate Jenkins container from the Nodejs container that orchestrates the app.
I solved this problem by running the container as root, as otherwise it would not have access to the Docker daemon socket /var/run/docker.sock ...