Created
May 5, 2018 11:31
-
-
Save stepankuzmin/4b71c657ef409d9b0b357d25e1dd74c9 to your computer and use it in GitHub Desktop.
Example docker usage from NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const request = require("request-promise"); | |
| const main = async () => { | |
| try { | |
| const { Id, Warnings } = await request({ | |
| method: 'POST', | |
| uri: 'http://unix:/var/run/docker.sock:/v1.24/containers/create', | |
| body: { Image: 'bfirsh/reticulate-splines' }, | |
| headers: { | |
| 'Host': null, | |
| // 'Host': 'localhost', | |
| 'Content-Type': 'application/json' | |
| }, | |
| json: true | |
| }); | |
| if (Warnings) { | |
| console.log('Warnings:', Warnings); | |
| } | |
| await request({ | |
| method: 'POST', | |
| uri: `http://unix:/var/run/docker.sock:/v1.24/containers/${Id}/start`, | |
| headers: { | |
| 'Host': null | |
| } | |
| }); | |
| console.log('Id', Id); | |
| } catch (e) { | |
| console.error(e); | |
| } | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment