Docker in Docker: Credential Passing

Hi,

I have three containers.

Jenkins-agent, which has already done docker login via $(aws ecr get-login --no-include-email)

Jenkins-agent is pulling Maven Image(from docker hub)

docker run --rm -v “${WORKSPACE}:/opt/app” -v /var/run/docker.sock:/var/run/docker.sock maven bin/bash run the test

Maven container is running a java unit test, which pulls an image from AWS ECR.

The question is, how can I pass my docker credential from Jenkins-agent container to maven container so that it can pull the image from ECR.

One of the solution is to pass aws credential to the maven container so that it can login again. But is there a better way to do it like mounting docker credential to the inner container, similar to -v /var/run/docker.sock:/var/run/docker.sock. ?

Thanks