You can update the composer version by Docker with the help of PHP CLI Container.
Let’s start by checking your docker available image with the help of command, docker ps.
You can see a list of available Container IDs with details of each IMAGE, and NAMES section.
You have to just copy the NAMES of your PHP CLI container, For me in my Magento project, the php-cli container image name looks like, magento2_php-cli_1
Now you can just log in with your CLI container,
docker exec -it -u <USERNAME> magento2_php-cli_1 bash (Example with root username: docker exec -it -u root magento2_php-cli_1 bash)
Now you can just log in with your PHP-CLI container,
You can upgrade the composer version by simply typing a command,
composer self-update --2
It will automatically fetch the latest version of the composer for your project.