Global

Methods

(async) pullImage(options) → {Promise.<(void|Error)>}

Description:
  • Pulls a Docker image using Dockerode.

Source:
Example
pullImage({
  docker: new Docker(),
  logger: Logger("my-logger"),
  imageName: "my-image",
}).then(() => {
  console.log("Image pulled successfully");
}).catch(error => {
  console.error("Error pulling image:", error);
});
Parameters:
Name Type Description
options Object

The parameters for pulling the image.

Properties
Name Type Attributes Default Description
docker Docker <optional>
new Docker({ socketPath: "/var/run/docker.sock" })

The Dockerode instance.

logger Logger <optional>
Logger("test-containers")

The Logger instance.

imageName string

The name of the Docker image to pull.

Returns:

A promise that resolves when the image is successfully pulled, or rejects with an error.

Type
Promise.<(void|Error)>

(async) runApplication(options) → {Promise.<(string|Error)>}

Description:
  • Runs an application in a Docker container.

Source:
Example
const scriptReadStream = fs.createReadStream("/path/to/your/script.tar.gz");
const execOptions = {
  Cmd: ["node", "yourScript.js"],
  AttachStdout: true,
  AttachStderr: true
};
runApplication({
  docker,
  containerName: "myContainer",
  scriptReadStream,
  execOptions
}).then(console.log).catch(console.error);
Parameters:
Name Type Description
options Object

The options for running the application.

Properties
Name Type Attributes Default Description
docker Docker <optional>
new Docker({ socketPath: "/var/run/docker.sock" })

The Docker instance to use.

logger Logger <optional>
Logger("test-containers")

The logger to use.

containerName string

The name of the container to run the application in.

scriptReadStream ReadableStream

The readable stream of the compressed file containing the application to run.

scriptRootDir string <optional>
"/root"

The root directory in the container to place and expand the archive.

execOptions Object

The options for executing the application in the container.

Returns:

A promise that resolves with the output of the script, or rejects with an error.

Type
Promise.<(string|Error)>

(async) startContainer(options) → {Promise.<(void|Error)>}

Description:
  • Starts a Docker container using Dockerode.

Source:
Example
startContainer({
  docker: new Docker(),
  logger: Logger("my-logger"),
  imageName: "my-image",
  containerOptions: {
    name: "my-container",
    ExposedPorts: {
      "8080/tcp": {}
    },
    HostConfig: {
      PortBindings: {
        "8080/tcp": [
          {
            HostPort: "8080"
          }
        ]
      }
    }
  }
}).then(container => {
  console.log("Container started:", container)
}).catch(error => {
  console.error("Error starting container:", error);
});
Parameters:
Name Type Description
options Object

The parameters for starting the container.

Properties
Name Type Attributes Default Description
docker Docker <optional>
new Docker({ socketPath: "/var/run/docker.sock" })

The Dockerode instance.

logger Logger <optional>
Logger("test-containers")

The Logger instance.

containerOptions Object <optional>
{}

The options for creating the container.

imageName string

The name of the Docker image to use.

Returns:

A promise that resolves when container is successfully started, or rejects with an error.

Type
Promise.<(void|Error)>

(async) stopContainer(options) → {Promise.<(void|Error)>}

Description:
  • Stops a Docker container using Dockerode.

Source:
Example
stopContainer({
  docker: new Docker(),
  logger: Logger("my-logger"),
  containerName: "my-container",
}).then(() => {
  console.log("Container stopped successfully")
}).catch(error => {
  console.error("Error stopping container:", error);
});
Parameters:
Name Type Description
options Object

The parameters for stopping the container. Default: {}.

Properties
Name Type Attributes Default Description
docker Docker <optional>
new Docker({ socketPath: "/var/run/docker.sock" })

The Dockerode instance.

logger Logger <optional>
Logger("test-containers")

The Logger instance.

removeContainer boolean <optional>
false

A boolean indicating whether to remove the container after stopping it. Default: false.

containerName string

The name of the Docker container to stop. No default value.

Returns:

A promise that resolves when the container is successfully stopped and removed, or rejects with an error if the container cannot be stopped or removed.

Type
Promise.<(void|Error)>