Search in sources :

Example 1 with ImageNotFoundException

use of com.spotify.docker.client.ImageNotFoundException in project hale by halestudio.

the class HaleDockerClient method startContainer.

/**
 * start a container. Container can be started in the privileged mode if the
 * 'isPrivileged' key in the configuration is set as true.
 *
 * @throws DockerException docker exception
 * @throws InterruptedException interrupted exception
 */
public void startContainer() throws DockerException, InterruptedException {
    try {
        dc.inspectImage(containerConf.image());
    } catch (ImageNotFoundException e) {
        // pull image if it is not present
        LOGGER.info(MessageFormat.format("Docker image not found, attempting to pull image {0}...", containerConf.image()));
        dc.pull(containerConf.image());
    }
    // TODO also add a setting to pull the image always?
    LOGGER.info(MessageFormat.format("Preparing container for image {0}...", containerConf.image()));
    creation = dc.createContainer(containerConf);
    containerId = creation.id();
    LOGGER.info(MessageFormat.format("Created container with ID {0}, now starting...", containerId));
    final HostConfig hostConfig;
    if (getHostName() == null) {
        // don't publish ports (probably unix socket connection)
        hostConfig = HostConfig.builder().publishAllPorts(false).privileged(dbc.isPrivileged()).build();
    } else {
        // XXX publishing all ports can be very bad if the host is
        // accessible externally
        hostConfig = HostConfig.builder().publishAllPorts(dbc.isExposeAllPorts()).privileged(dbc.isPrivileged()).build();
    }
    dc.startContainer(containerId, hostConfig);
    final ContainerInfo info = dc.inspectContainer(containerId);
    portMapper = info.networkSettings().ports();
    containerIp = info.networkSettings().ipAddress();
}
Also used : HostConfig(com.spotify.docker.client.messages.HostConfig) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) ImageNotFoundException(com.spotify.docker.client.ImageNotFoundException)

Aggregations

ImageNotFoundException (com.spotify.docker.client.ImageNotFoundException)1 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)1 HostConfig (com.spotify.docker.client.messages.HostConfig)1