/** * Run a command inside a running container, as though using "docker exec", and interpreting * the output as UTF8. * <p></p> * @param containerInfo the container info * @param command the command to execute * @see #execInContainer(InspectContainerResponse, Charset, String...) */ public Container.ExecResult execInContainer(InspectContainerResponse containerInfo, String... command) throws UnsupportedOperationException, IOException, InterruptedException { return execInContainer(containerInfo, Charset.forName("UTF-8"), command); }
if (!isRunning(containerInfo)) { throw new IllegalStateException("execInContainer can only be used while the Container is running");
if (!isRunning(containerInfo)) { throw new IllegalStateException("execInContainer can only be used while the Container is running");
/** * {@inheritDoc} */ @Override public ExecResult execInContainer(Charset outputCharset, String... command) throws UnsupportedOperationException, IOException, InterruptedException { return ExecInContainerPattern.execInContainer(getContainerInfo(), outputCharset, command); }
private void tryPort(Integer internalPort) { String[][] commands = { {"/bin/sh", "-c", format("cat /proc/net/tcp{,6} | awk '{print $2}' | grep -i :%x && echo %s", internalPort, SUCCESS_MARKER)}, {"/bin/sh", "-c", format("nc -vz -w 1 localhost %d && echo %s", internalPort, SUCCESS_MARKER)}, {"/bin/bash", "-c", format("</dev/tcp/localhost/%d && echo %s", internalPort, SUCCESS_MARKER)} }; for (String[] command : commands) { try { if (ExecInContainerPattern.execInContainer(waitStrategyTarget.getContainerInfo(), command).getStdout().contains(SUCCESS_MARKER)) { return; } } catch (Exception e) { throw new IllegalStateException(e); } } throw new IllegalStateException("Socket not listening yet: " + internalPort); } }
/** * Run a command inside a running container, as though using "docker exec", and interpreting * the output as UTF8. * <p></p> * @param containerInfo the container info * @param command the command to execute * @see #execInContainer(InspectContainerResponse, Charset, String...) */ public static Container.ExecResult execInContainer(InspectContainerResponse containerInfo, String... command) throws UnsupportedOperationException, IOException, InterruptedException { return execInContainer(containerInfo, Charset.forName("UTF-8"), command); }
private void tryPort(Integer internalPort) { String[][] commands = {{"/bin/sh", "-c", format("cat /proc/net/tcp{,6} | awk \'{print $2}\' | grep -i :%x && echo %s", internalPort, SUCCESS_MARKER)}, {"/bin/sh", "-c", format("nc -vz -w 1 localhost %d && echo %s", internalPort, SUCCESS_MARKER)}, {"/bin/bash", "-c", format("</dev/tcp/localhost/%d && echo %s", internalPort, SUCCESS_MARKER)}}; for (String[] command : commands) { try { if (ExecInContainerPattern.execInContainer(waitStrategyTarget.getContainerInfo(), command).getStdout().contains(SUCCESS_MARKER)) { return; } } catch (Exception e) { throw new IllegalStateException(e); } } throw new IllegalStateException("Socket not listening yet: " + internalPort); }