I am trying to execute chmod
command from Java in a running Docker container:
String cmd = "docker exec -it " + POSTGRES_CONTAINER_NAME + " bash -c 'chmod +x /tmp/dump.sh'";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));
for (String line = br.readLine(); line != null; line = br.readLine()) {
LOGGER.debug("L:{}", line);
}
There is a problem because execution flag is not set (and I am not getting any message from docker exec
).
docker exec -it postgres_intm bash -c "ls -la /tmp/dump.sh"
-rw-r--r-- 1 root root 134 Jun 4 20:59 /tmp/dump.sh
When I call a chmod
from command line manually, an execution permission is set correctly:
docker exec -it postgres_intm bash -c 'chmod +x /tmp/dump.sh'
docker exec -it postgres_intm bash -c "ls -la /tmp/dump.sh"
-rwxr-xr-x 1 root root 134 Jun 4 20:59 /tmp/dump.sh
Q: What am I doing wrong that Java code doesn’t set a execution permission?