testcontainers / testcontainers/testcontainers-java
Starting docker-compose test containers as non-root user
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
Similar to: https://github.com/testcontainers/testcontainers-java/issues/2590
I'm trying to start our docker-compose based testcontainers tests, and pass in the local username from the running system, in order that the container can write files to mounted volumes with the correct permissions.
I tried a compose with:
version: "3.7"
services:
myservice:
image: xxx
user: ${CURRENT_USER}
...
volumes:
./target/:/target
And passed in CURRENT_USER environment variable to testcontainers using:
env = new DockerComposeContainer(new File("src/main/docker/docker-compose.yml"));
env.withLocalCompose(true);
env.withEnv("CURRENT_USER", System.getProperty("user.name"));
However, this fails with:
Cannot start service my server: unable to find user bmiddleton: no matching entries in passwd file
I presume it's looking for that user in the ryuk container, and not the OS - where the user does exist.
How can I get a testcontainers test running from a docker compose file to write its files using the current user of the operating system?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the DockerComposeContainer setup using src/main/docker/docker-compose.yml, including withLocalCompose(true) and withEnv("CURRENT_USER", System.getProperty("user.name")). Reproduce the compose-based test failure and inspect how the compose service user and mounted ./target/ volume are handled. Done means the service can write mounted files with the current OS user's permissions without the passwd lookup error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, docker-compose, java
- Domain
- devops, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100