Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Teamcity Build won't run until Build Agents is configured with Docker?

I created a new build for my Teamcity pipeline. For the first time I use then Docker buildstep. After I setup everything I realized the build agent does not seem to be ready for it.

enter image description here

I understand that my agent does not seem to be ready for building with docker but nobody is actually telling me how you can do that. I read the official guides but no word about how to actually install docker into my agent (if that's the way to solve the problem).

Can someone tell me what I have to do to get it to work?

EDIT

@Senior Pomidor helped me to get one step closer. I added his first example to the docker run command

docker run -it -e SERVER_URL="<url to TeamCity server>"  \
    --privileged -e DOCKER_IN_DOCKER=start \    
    jetbrains/teamcity-agent 

After doing so I got rid of the mentioned messages in the screenshot. My Agents configuration now has the following:

docker.server.osType     linux
docker.server.version    18.06.1
docker.version   18.06.1

But still Teamcity is complaining with this message:

enter image description here

Which kinda leaves me clueless again.

Final Solution: The upcoming EDIT2 issue could be resolved by just restarting the teamcity server instance. The agent was actually able to run the build but teamcity was not able to realise that without a reboot.

EDIT2

Request Information:

My CI Server OS:

PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"

Running Container:

CONTAINER ID        IMAGE                       COMMAND              CREATED             STATUS              PORTS                  NAMES
0f8e0b04d6a6        jetbrains/teamcity-agent    "/run-services.sh"   19 hours ago        Up 19 hours         9090/tcp               teamcity-agent
20964c22b2d9        jetbrains/teamcity-server   "/run-services.sh"   37 hours ago        Up 37 hours         0.0.0.0:80->8111/tcp   teamcity-server-instance

Container run by:

## Server
docker run -dit --name teamcity-server-instance  -v /data/teamcity:/data/teamcity_server/datadir -v /var/log/teamcity:/opt/teamcity/logs  -p 80:8111 jetbrains/teamcity-server

## Agent
docker run -itd --name teamcity-agent -e SERVER_URL="XXX.XXX.XXX.XXX:80"  --privileged -e DOCKER_IN_DOCKER=start -v /etc/teamcity/agent/conf:/data/teamcity_agent/conf jetbrains/teamcity-agent

Build Step Information:

enter image description here enter image description here enter image description here

like image 596
xetra11 Avatar asked Dec 23 '22 23:12

xetra11


2 Answers

TC restricted the configuration because of TA doesn't start Docker daemon.

You should pass -e DOCKER_IN_DOCKER=start for automatically staring the docker daemon in the container. Also, docker daemon needs the docker socket. In a Linux container, if you need a Docker daemon available inside your builds, you have two options:

  • --privileged flag. New Docker daemon running within your container
  • -v docker_volumes:/var/lib/docker Docker from the host (in this case you will benefit from the caches shared between the host and all your containers but there is a security concern: your build may actually harm your host Docker, so use it at your own risk)

In a Linux container, if you need a Docker daemon available inside your builds, you have two options:

  1. Docker from the host (in this case you will benefit from the caches shared between the host and all your containers but there is a security concern: your build may actually harm your host Docker, so use it at your own risk)

examples

docker run -it -e SERVER_URL="<url to TeamCity server>"  \
    --privileged -e DOCKER_IN_DOCKER=start \    
    jetbrains/teamcity-agent 

docker run -it -e SERVER_URL="<url to TeamCity server>"  \
    -v /var/run/docker.sock:/var/run/docker.sock  \
    jetbrains/teamcity-agent 

UPD

docker.server.osType required because in the build step was sets linux

like image 160
Senior Pomidor Avatar answered Dec 26 '22 11:12

Senior Pomidor


What worked for me was changing permissions on the agent container for /var/run/docker.sock

Run a shell inside the container: docker exec -u 0 -it <CONTAINER_ID> bash

Change permissions of the docker socket: chmod 666 /var/run/docker.sock

Verify the docker container use the socket: docker version

like image 25
Andrew Avatar answered Dec 26 '22 10:12

Andrew