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?
Please sign in to leave a comment.
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 ):
Change whatever you need
Exit and create a new image from the container:
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.
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:
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):
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:
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:
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:
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:
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.
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.
In case it is useful, it is also possible to build the image using docker build.
An example Dockerfile would be something like:
Then use the following Docker command to build the image:
After the build is complete, you can run the agent using the <desired name>:<desired tag> that was used in the previous step.