How to identify the number of scaled container

You don’t have any volume statements in your compose file. Also, you environment statement is wrong. Maybe something like this:

version: '2'

services:
    agent:
        build: agent_image
        image: teamcity_agent:1.4
        environment:
        - AGENT_NUMBER
        volumes:
          - ./config_${AGENT_NUMBER}:/teamcity/config
          - ./work_${AGENT_NUMBER}:/teamcity/work
        restart: always

Where the you have the config_1, config_2, work_1, work_2, etc. folders in the same place as the yml file. Adjust the paths on the left side of the volume statements if this is not the case. Adjust the right side of the volume statements to put them in the right place inside the container.

one extra thing though, does the work folder really need to be outside the container? Do it need to be persisted across container runs?