How to upgrade JDK in Docker compose TeamCity 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?

0
4 comments

Hi,

It is not possible to replace the provided Java 11 with Java 17, as the Build Agent still requires Java 11. However, you can certainly customize the Docker image to have both Java 11 and 17. There are several ways to configure which Java the Build Agent will run on, please refer to Path to Java on Agent Machine for details on how to configure the Build Agent Java. 

With Java 17 installed on the Build Agent, you'll be able to use Java 17 in your builds, even though the Build Agent is running on Java 11. 

You can customize the image via the usual Docker procedure ( from the official Docker Hub page ):

  1. Run the image
docker run -e SERVER_URL="<url to TeamCity server>"  \ 
    -v <path to agent config folder>:/data/teamcity_agent/conf  \
    --name="my-customized-agent"  \
    jetbrains/teamcity-minimal-agent  \
  1. Enter the container
docker exec -it my-customized-agent bash
  1. Change whatever you need 

  2. Exit and create a new image from the container:

docker commit my-customized-agent <the registry where you what to store the image>
1

3. Change whatever you need

That's the magic part, and for those of us who aren't Ubuntu experts, the part that's over our heads (at least my head), especially the limited form of Ubuntu that the TC Agent image is using. Installing an additional JDK and making it discoverable by builds is far from trivial for those of us.

Is there no plan for JetBrains to provide a Java 17-compatible image for agents? Seems like an obvious win for the user base, and probably trivial for an experienced Ubuntu sys admin that I'm sure you have on staff.

0

That's the magic part, and for those of us who aren't Ubuntu experts, the part that's over our heads (at least my head), especially the limited form of Ubuntu that the TC Agent image is using. Installing an additional JDK and making it discoverable by builds is far from trivial for those of us.

The version of Ubuntu used in the TC Agent is just the base Ubuntu Docker image. It is not exactly limited, but being a Docker base image, it doesn't contain any packages that are not explicitly installed in order to reduce the size of the image. The process of installing Java 17 would be the same as any non-docker Ubuntu image. You can find instructions on installing Amazon Corretto 17 here: https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/generic-linux-install.html. 

After starting the docker container with:

docker run -d -e SERVER_URL=<teamcity url> jetbrains/teamcity-agent

You can then enter the container as root to perform the installation using this command (the -u 0 part tells Docker that you want to run the command as root):

docker exec -it -u 0 <container ID> bash

From there, if you want to follow the Amazon Corretto instructions, you'll need to install wget. You can do that with the following command:

apt update && apt install wget -y

Keep in mind, when you're logged into your container as root, you do not use the 'sudo' command. So the rest of the installation would be like this:

# wget -O- https://apt.corretto.aws/corretto.key | apt-key add -
# add-apt-repository 'deb https://apt.corretto.aws stable main'
# apt-get update; apt-get install -y java-17-amazon-corretto-jdk

After the Java installation is complete, it's a good idea to remove wget as well as the apt cache. This will keep the image as small as possible. You can remove both of these with the following:

apt remove wget -y && rm -rf /var/lib/apt/lists/*

Once you have things how you want them in the container, you can then exit from the container using the 'exit' command, and commit your image:

docker commit <container ID> <the registry where you what to store the image>

When your build agent starts up, it will automatically detect the Java 17 installation and report it to the TeamCity server upon connection. This will allow you to select Java 17 to be used in your build runners.

 

Is there no plan for JetBrains to provide a Java 17-compatible image for agents? Seems like an obvious win for the user base, and probably trivial for an experienced Ubuntu sys admin that I'm sure you have on staff.

We do have this on our YouTrack here: https://youtrack.jetbrains.com/issue/TW-72037/Support-Java-17-for-TeamCity-Agents.

If this is something you'd like to see, please take a moment to vote/comment on the YouTrack issue. Our developers use the information on our YouTrack site to determine which features are included in future releases. Additionally, any comments left on YouTrack issues are routed directly to the responsible developers, so it is a great place to leave a note with your use-case.

0

In case it is useful, it is also possible to build the image using docker build.

An example Dockerfile would be something like:

FROM jetbrains/teamcity-agent:latest

USER root

RUN apt-get update && apt-get install wget -y && \
wget -O- https://apt.corretto.aws/corretto.key | apt-key add - && \
add-apt-repository 'deb https://apt.corretto.aws stable main' && \
apt-get update; apt-get install -y java-17-amazon-corretto-jdk && \
apt-get remove wget -y && rm -rf /var/lib/apt/lists/*

USER buildagent

Then use the following Docker command to build the image:

docker build -t "<desired name>:<desired tag>" .

After the build is complete, you can run the agent using the <desired name>:<desired tag> that was used in the previous step. 

0

Please sign in to leave a comment.