Stack Exchange
How to upgrade JDK in Docker compose container?
I have this docker-compose.yml configuration file for TeamCity - server and agent.
version: "3.5"
services:
  server:
    image: jetbrains/teamcity-server:latest
    container_name: teamcity_server
    networks:
      - teamcity_network
    ports:
      - "8111:8111"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - datadir:/data/teamcity_server/datadir
      - logs:/opt/teamcity/logs
    environment:
      TEAMCITY_SERVER_MEM_OPTS: -Xmx1024m
  agent:
    image: jetbrains/teamcity-agent:latest
    container_name: teamcity_agent
    volumes:
      - agent_conf:/data/teamcity_agent/conf
    environment:
      - SERVER_URL=http://example.com:8111
networks:
  teamcity_network:
volumes:
  datadir:
  logs:
  agent_conf: 

TeamCity server and agent start correctly, I can login, create projects, connect to Git repository etc.
But my Java application needs Java 17, and TeamCity docker images provide Java 11. I tried to do upgrade, and logged in into docker Ubuntu docker exec -it <mycontainerId> bash but I am user and I have no system privileges to update Java in the container.
Question: How can I install Java 17 into container and replace Java 11 to Java 17? Or is there configuration option for docker-compose.yml to install Java 17 instead of 11?

You shouldn't update the JDK version of the TeamCity server - you generally don't want to modify the server dependencies as that may cause instability.
What you are supposed to be doing (and the example compose file kind of shows it) is to use the agent container to run your build, or more correctly - build a new image - based on the agent image (i.e. uses FROM jetbrains/teamcity-agent:latest) - where you install whatever tools you need for your build.
The agent images are also locked to a user, but they install sudo so you should be able to use that to build an image with updated JDK. Another alternative is to build a completely new image for the agent by copying the open source TeamCity agent Docker file from their Github repository and updating it as needed.

It seems sudo is not installed in agent container: buildagent@fa1bbaece89b:/$ sudo cd /root/ bash: sudo: command not found

Correct - the minimal agent (that I linked to) does include sudo.

Hmm.. the Dockerfile they have in Github definitely is installing sudo, but that doesn't seem to be what you get when you docker pull jetbrains/teamcity-minimal-agent... I suggest copying their Dockerfile and modifying it for your needs - don't use the agents from the Docker Hub.

They have some tags for jetbrains/teamcity-agent that include sudo - they can be identified by the tag name ending with -sudo, but they unfortunately don't publish a latest-sudo tag.

Thank you, I will try to create own image as you described - https://github.com/JetBrains/teamcity-docker-images/blob/master/dockerhub/teamcity-minimal-agent/README.md
