I want azure devops container agent always idle and should be running.
but it is only running as long build pipeline is running. after that it is existing. so in order to avoid that I added below command in the docker file in the end. but agent is gone after pipeiine run
CMD [“tail”, “-f”, “/dev/null”]
Dockerfile:
# Another option:
# FROM arm64v8/alpine
# ENV TARGETARCH="linux-musl-arm64"
RUN apk update && apk upgrade
# Installing OpenJDK 11, Node.js, and other required packages
RUN apk add --no-cache bash curl git icu-libs jq openjdk17-jre nodejs npm
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk
ENV PATH="$JAVA_HOME/bin:$PATH"
# Verify Java and Node.js installations
RUN java -version && node -v && npm -v
WORKDIR /azp/
COPY ./start.sh ./
RUN chmod +x ./start.sh
RUN adduser -D agent
RUN chown agent ./
USER agent
# Another option is to run the agent as root.
# ENV AGENT_ALLOW_RUNASROOT="true"
ENTRYPOINT [ "./start.sh" ]
CMD ["tail", "-f", "/dev/null"]
Please suggest way to run container agent idle even when pipeline build completed.
I removed -f /dev/null and added in the start.sh file in the end.
but still respective container agent got deleted from agents section and you can see here below
No…
Either you run the docker container attached to your terminal, in which case your terminal will display the container’s process.
since your process never ends with tail -f /dev/null, the container never ends, and your terminal stays attached to the container
If you run the container DETACHED, then your terminal will be free to run other tasks as your container stays up
@deanayalon I see agent is available now in devops agent section, I noticed it is taking 5 min to come up.
Thank you.
I did not figure out this earlier
and to add one more point i Just noticed that when I use below docker file, it is running even container exists.
shyam@DESKTOP-OO7EVK2:~/azp-agent-in-docker$ cat Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:5.0
# Install curl
RUN apt-get update && apt-get install -y curl
# Copy your application code and script
COPY . /app
# Set the working directory
WORKDIR /app
# Ensure the script is executable
RUN chmod +x start.sh
# Use a shell form entrypoint to run the script and then the .NET application
# Run start.sh and then dotnet run; ensure dotnet run stays in the foreground
CMD ["/bin/sh", "-c", "./start.sh && dotnet run"]
and when I execute below docker file container is not getting killed.
FROM alpine:latest
ENV TARGETARCH="linux-musl-x64"
# Another option:
# FROM arm64v8/alpine
# ENV TARGETARCH="linux-musl-arm64"
RUN apk update && apk upgrade
# Installing OpenJDK 11, Node.js, and other required packages
RUN apk add --no-cache bash curl git icu-libs jq openjdk17-jre nodejs npm
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk
ENV PATH="$JAVA_HOME/bin:$PATH"
# Verify Java and Node.js installations
RUN java -version && node -v && npm -v
WORKDIR /azp/
COPY ./start.sh ./
RUN chmod +x ./start.sh
RUN adduser -D agent
RUN chown agent ./
USER agent
# Another option is to run the agent as root.
# ENV AGENT_ALLOW_RUNASROOT="true"
ENTRYPOINT [ "./start.sh" ]
in order make sure container run with out existing i tried to add cmd and dotnet run test in the command section but first dockerfile above is making container to kill when i ran it
COuld you please suggest what exactly need to amend/add in dockerfile 1 in the above to makue container running with out exist
So you try to do what Microsoft documented here on your own?
Though, your start.sh looks incomplete compared to the one from the documentation.
And I love this note in the documentation:
You must also use a container orchestration system, like Kubernetes or Azure Container Instances, to start new copies of the container when the work completes.