2.0.1 • Published 4 years ago
sidelifter v2.0.1
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:password@127.0.0.1:${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)
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.