sidelifter
v2.0.1
Published
Utilities for working with Docker containers
Readme
sidelifter
Utilities for working with Docker containers
Example
import * as path from 'path'
import { startContainer, removeContainer } from 'sidelifter'
import { openDatabase } from 'rumor-mill'
async function run() {
const container = await startContainer({
image: 'mysql:5',
env: {
MYSQL_RANDOM_ROOT_PASSWORD: '1',
MYSQL_DATABASE: 'database',
MYSQL_USER: 'user',
MYSQL_PASSWORD: 'password'
},
mount: {
[path.resolve()]: '/root/app'
}
})
const localPort = container.ports.get(3306)
const db = await openDatabase(`mysql://user:[email protected]:${localPort}/database`)
await removeContainer(container)
}
run()Usage
Install sidelifter by running:
yarn add sidelifterActions
startContainer(options)
Pulls an image, creates a container, and starts the container.
Readable streams container.stdout and container.stderr are provided. A
writable stream container.stdin is also provided.
Mapped ports are provided as container.ports via Map from container port to
host port.
Parameters
options(object)image(string): The name and tag of a Docker imageenv({ [string]: string }): Environment variables to be set within the containermount({ [string]: string }): Directories to mount within the containercmd(Array): An optional command to run within the Docker container
Returns
container(Promise)
waitForContainer(container)
Waits for the Cmd that the container is running to exit.
Parameters
container(Container)
Returns
promise(Promise)
removeContainer(container)
Stops and destroys the container.
Parameters
container(Container)
Returns
promise(Promise)
Debugging
Debug logging can be enabled by setting the environment variable
NODE_DEBUG=sidelifter.
See the Node.js documentation for more information.
