Class DUUIDockerInterface
java.lang.Object
org.texttechnologylab.DockerUnifiedUIMAInterface.DUUIDockerInterface
This is the general docker interface which interacts with the docker daemon.
-
Constructor Summary
ConstructorDescriptionCreates a default object which connects to the local docker daemon, may need admin rights depending on the docker installation Depending on the Operating System a different connection URI is used to build the DockerClient. -
Method Summary
Modifier and TypeMethodDescriptionvoid
export_to_new_image
(String containerid, String imagename) Exports a running container to a new image.int
extract_port_mapping
(String containerid) Extracts port mapping from the container with the given containerid, this is important since docker does auto allocate ports when not explicitly specifying the port number.int
extract_port_mapping
(String containerid, int portMapping) Extracts port mapping from the container with the given containerid, this is important since docker does auto allocate ports when not explicitly specifying the port number.int
extract_service_port_mapping
(String service) get_ip()
Reads the container gateway bridge ip if inside the container to enable communication between sibling containers or the localhost ip if one is the host.Reads the logs from the container to determine if the container has started up without errorsgetDigestFromImage
(String imagename) com.github.dockerjava.api.DockerClient
com.github.dockerjava.api.model.Image
getLocalImage
(String imageName) boolean
hasLocalImage
(String imageName) boolean
Returns true if the code is run inside the container and false otherwise.boolean
pullImage
(String tag, String username, String password, AtomicBoolean shutdown) Attempts to pull a docker image using its tag, and credentials if necessary.void
push_image
(String remoteName, String localName, String username, String password) void
rm_service
(String id) Stops the container with the given container idBuilds and runs the container with a specified temporary build directory and some flags.run
(String imageid, boolean gpu, boolean autoremove, int portContainer, int portHost, boolean mapDaemon) Builds and runs the container with a specified temporary build directory and some flags.run_service
(String imagename, int scale) run_service
(String imagename, int scale, List<String> constraints) void
stop_container
(String id) Stops the container with the given container id
-
Constructor Details
-
DUUIDockerInterface
Creates a default object which connects to the local docker daemon, may need admin rights depending on the docker installation Depending on the Operating System a different connection URI is used to build the DockerClient. On Windows the npipe protocol is required to establish a connection with the docker daemon.- Throws:
IOException
-
-
Method Details
-
extract_port_mapping
Extracts port mapping from the container with the given containerid, this is important since docker does auto allocate ports when not explicitly specifying the port number. This will only work on a DockerWrapper constructed container.- Parameters:
containerid
- The running containerid to read the port mapping from- Returns:
- The port it was mapped to.
- Throws:
InterruptedException
-
extract_port_mapping
Extracts port mapping from the container with the given containerid, this is important since docker does auto allocate ports when not explicitly specifying the port number. This will only work on a DockerWrapper constructed container.- Parameters:
containerid
- The running containerid to read the port mapping from- Returns:
- The port it was mapped to.
- Throws:
InterruptedException
-
extract_service_port_mapping
- Throws:
InterruptedException
-
inside_container
public boolean inside_container()Returns true if the code is run inside the container and false otherwise.- Returns:
- true if in container false otherwise
-
get_ip
Reads the container gateway bridge ip if inside the container to enable communication between sibling containers or the localhost ip if one is the host.- Returns:
- The ip address.
-
get_logs
Reads the logs from the container to determine if the container has started up without errors- Parameters:
containerid
- The container id to check the logs from- Returns:
- The string representation of the read logs
- Throws:
InterruptedException
-
stop_container
Stops the container with the given container id- Parameters:
id
- The id of the container to stop.
-
rm_service
Stops the container with the given container id- Parameters:
id
- The id of the container to stop.
-
export_to_new_image
Exports a running container to a new image.- Parameters:
containerid
- The containerid to commit to a new imageimagename
- The image name in the format "repository!imagename"
-
getLocalImage
-
push_image
public void push_image(String remoteName, String localName, String username, String password) throws InterruptedException - Throws:
InterruptedException
-
run_service
- Throws:
InterruptedException
-
run_service
public String run_service(String imagename, int scale, List<String> constraints) throws InterruptedException - Throws:
InterruptedException
-
hasLocalImage
-
getDockerClient
public com.github.dockerjava.api.DockerClient getDockerClient() -
build
-
isSwarmManagerNode
public boolean isSwarmManagerNode() -
pullImage
- Throws:
InterruptedException
-
pullImage
- Throws:
InterruptedException
-
pullImage
public String pullImage(String tag, String username, String password, AtomicBoolean shutdown) throws InterruptedException Attempts to pull a docker image using its tag, and credentials if necessary.- Parameters:
tag
- The unique identifier of the image (uri:version).username
- Credentials username.password
- Credentials password.shutdown
- A flag to signal a pull cancel.- Returns:
- The image tag.
- Throws:
InterruptedException
-
getDigestFromImage
-
run
public String run(String imageid, boolean gpu, boolean autoremove, int port, boolean mapDaemon) throws InterruptedException Builds and runs the container with a specified temporary build directory and some flags.- Parameters:
gpu
- If the gpu should be usedautoremove
- If the autoremove flag is set for the container- Returns:
- The docker container id
- Throws:
InterruptedException
-
run
public String run(String imageid, boolean gpu, boolean autoremove, int portContainer, int portHost, boolean mapDaemon) throws InterruptedException Builds and runs the container with a specified temporary build directory and some flags.- Parameters:
gpu
- If the gpu should be usedautoremove
- If the autoremove flag is set for the container- Returns:
- The docker container id
- Throws:
InterruptedException
-