Docker Compose DNS issues with Team City Agent

1.4k Views Asked by At

I have the following docker-compose.yml file that contains a Team City Server and Agent which I would like to run on my local Win 10 dev machine using Docker version 17.06.1-ce-win24 (13025):

version: '3.1'

services:
  tc_server:
    image: jetbrains/teamcity-server:2017.1.2
    ports: 
      - 8111:8111
    volumes:
      - teamcity_server:/data/teamcity_server/datadir
      - teamcity_server_logs:/opt/teamcity/logs
  tc_agent:
    image: jetbrains/teamcity-agent:2017.1.2
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - teamcity_agent_conf:/data/teamcity_agent/conf
    environment:
      SERVER_URL: http://tc_server:8111
volumes:
  teamcity_server:
  teamcity_server_logs:
  teamcity_agent_conf: 

The Team City Server and Agent start up but I can't see any unauthorised Agents in the UI.

I checked the docker logs:

tc_agent_1   | [2017-09-02 10:47:27,548]   WARN - buildServer.AGENT.registration - Error while asking server for the communication protocols via URL http://tc_server:8111/app/agents/protocols. Will try all protocols: java.net.ConnectException: Connection refused Connection refused) (enable debug to see stacktrace)
tc_agent_1   | [2017-09-02 10:47:27,549]   INFO - buildServer.AGENT.registration - Trying to register on server using 'polling' protocol.
tc_agent_1   | [2017-09-02 10:47:27,570]   INFO - buildServer.AGENT.registration - Registration using 'polling' protocol failed: java.net.ConnectException: Connection refused (Connection refused) (enable debug to see stacktrace)
tc_agent_1   | [2017-09-02 10:47:27,570]   INFO - buildServer.AGENT.registration - Trying to register on server using 'xml-rpc' protocol.
tc_agent_1   | [2017-09-02 10:47:27,581]   INFO - buildServer.AGENT.registration - Registration using 'xml-rpc' protocol failed: java.net.ConnectException: Connection refused (Connection refused) (enable debug to see stacktrace)
tc_agent_1   | [2017-09-02 10:47:27,581]   WARN - buildServer.AGENT.registration - Error registering on the server via URL http://tc_server:8111. Will continue repeating connection attempts.

It looks like the Agent can't connect to the Server, but running this command shows that the Agent container can resolve and retrieve from the TC Server container (contradicting the log warnings):

docker-compose exec tc_agent curl http://tc_server:8111/app/agents/protocols
<list><string>polling</string></list>

I tried removing the the Agent from the Docker-compose.yml file and span it up separately using Docker (tc_default is the network that the containers are using):

docker run --rm --network tc_default -e SERVER_URL=http://tc_server:8111 jetbrains/teamcity-agent:2017.1.2

This gave the same errors that were previously found in the logs. So I resorted to using the IP address of the server:

docker run --rm --network tc_default -e SERVER_URL=http://172.18.0.3:8111 jetbrains/teamcity-agent:2017.1.2

This worked, the Agent appeared in the Team City Unauthorised Agents list.

Is this a DNS issue with the Agent or am I using docker-compose networking incorrectly? I'd prefer to keep the Server and Agent in a single Docker-compose file if possible.

3

There are 3 best solutions below

0
On BEST ANSWER

Remove the _ form your service names and it should work. I have seen issues in python recently when using http://service_name:port didn't work. But using http://servername:port worked

Though _ in many libraries and places, it still doesn't work for all

0
On

Your tc_server needs to be started before the agent. Add the following inside the tc_agent service configuration, to ensure the startup sequence:

depends_on:
      - tc_server
0
On

Here's what worked for me

docker-compose.yml

version: '3.8'
# Define the services/containers to be run
services:
  teamcity: # name of the service 
    image: 'jetbrains/teamcity-server'
    container_name: 'tmserver' # name of the container
    restart: always
    ports: 
      - "8111:8111" # specify the teamcity port default is 8111
    volumes: # This will store the plugin setup config data.
      - teamcity_data:/data/teamcity_server/datadir # Host is location /var/lib/docker/volumes/USERNAME_teamcity_data
      - teamcity_data:/opt/teamcity/logs

  teamcityagent: # name of the service 
    image: 'jetbrains/teamcity-agent'
    container_name: 'tmagent' # name of the container
    restart: always
    volumes: # This will store the plugin setup config data. example: /var/lib/docker/volumes/developer_teamcity_agent_data/_data
      - teamcity_agent_data:/data/teamcity_agent/conf # Host location /var/lib/docker/volumes/USERNAME_teamcity_agent_data 
    depends_on: # tells the teamcity_server to start first before the agent 
      - teamcity
    environment:  # Set environment variables aka Server url
      - SERVER_URL=http://teamcity:8111/ # we use the name teamcity for the url so its a container to container connection

volumes:
  teamcity_data:
  teamcity_agent_data: