@Test
    public void extraHostTest() throws IOException {
        BufferedReader br = getReaderForContainerPort80(alpineExtrahost);

        // read hosts file from container
        StringBuffer hosts = new StringBuffer();
        String line = br.readLine();
        while (line != null) {
            hosts.append(line);
            hosts.append("\n");
            line = br.readLine();
        }

        Matcher matcher = Pattern.compile("^192.168.1.10\\s.*somehost", Pattern.MULTILINE).matcher(hosts.toString());
        assertThat(matcher.find()).as("The hosts file of container contains extra host").isTrue();
    }
Create a container with an extra host entry and expose the content of /etc/hosts for testing.
core/src/test/java/org/testcontainers/junit/GenericContainerRuleTest.java