Search code examples
dockernetworkingdocker-composeteamcity-9.0

Docker Compose DNS issues with Team City Agent


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.


Solution

  • 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