{"id":14235890,"url":"https://github.com/hugojosefson/docker-shebang","last_synced_at":"2025-07-30T17:33:04.051Z","repository":{"id":66830181,"uuid":"171042139","full_name":"hugojosefson/docker-shebang","owner":"hugojosefson","description":"Single-file script runner via Docker","archived":false,"fork":false,"pushed_at":"2019-11-01T23:37:52.000Z","size":30,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-17T01:21:08.903Z","etag":null,"topics":["bash","docker","hacktoberfest","node","nodejs","python","runner","script","shebang"],"latest_commit_sha":null,"homepage":"https://hugojosefson.github.io/docker-shebang/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hugojosefson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-02-16T19:19:28.000Z","updated_at":"2024-07-14T01:35:03.000Z","dependencies_parsed_at":"2023-02-23T01:30:30.729Z","dependency_job_id":null,"html_url":"https://github.com/hugojosefson/docker-shebang","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Fdocker-shebang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Fdocker-shebang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Fdocker-shebang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Fdocker-shebang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hugojosefson","download_url":"https://codeload.github.com/hugojosefson/docker-shebang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228165429,"owners_count":17879260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","docker","hacktoberfest","node","nodejs","python","runner","script","shebang"],"created_at":"2024-08-20T21:02:28.400Z","updated_at":"2024-12-04T18:20:36.568Z","avatar_url":"https://github.com/hugojosefson.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"# docker-shebang\n\nRun any self-contained single-file script, with any interpreter from the Docker ecosystem. Only Docker and `sh` are\nrequired to be installed locally.\n\nNo extra file nor runtime to install, besides Docker. Simply choose an example shebang+comment below, to paste at the\ntop of your script. Your script file will be fully self-contained!\n\nThis page has examples for:\n\n  * [Node.js](#nodejs)\n  * [Node.js with dependencies](#nodejs-with-npm-dependencies)\n  * [Python](#python)\n  * [Go (golang)](#go)\n  * [Rust](#rust)\n\nThese examples don't have access to your file system by default. You can enable files by un-commenting one of the\n`DOCKER_EXTRA_ARGS` lines, for read-only or read-write file access.\n\nExit codes, `stdin`, `stdout` and `stderr` should still work as expected, so you can always pipe data in and out.\n\n## Usage\n\nRemember to make each of your scripts executable:\n\n```sh\nchmod +x your-script.js\nchmod +x your-script.py\n```\n\nThen just run the script:\n\n```sh\n./your-script.js\n```\n```sh\n./your-script.py\n```\n\n### Node.js\n\nYou can set `DOCKER_IMAGE` to any compatible Docker image with `node`. Suggested: [node](https://hub.docker.com/_/node).\n                   \nPaste this shebang line and comment at the beginning of your `.js` script file:\n\n```js\n#!/usr/bin/env sh\n/* 2\u003e/dev/null\nDOCKER_IMAGE=node:lts\nDOCKER_CMD=\"node\"\n\n## Optionally, un-comment one of these lines to give access to current directory, read-only or read-write:\n# DOCKER_EXTRA_ARGS=\"-w $(pwd) -u $(id -u):$(id -g) -v $(pwd):$(pwd):ro\"\n# DOCKER_EXTRA_ARGS=\"-w $(pwd) -u $(id -u):$(id -g) -v $(pwd):$(pwd):rw\"\n\ns=\"$(cd \"$(dirname \"$0\")\" \u0026\u0026 pwd)/$(basename \"$0\")\";docker run --rm -a stdin -a stdout -a stderr -i$([ -t 0 ] \u0026\u0026 echo t) --init -v \"$s\":\"$s\":ro ${DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} ${DOCKER_CMD} \"$s\" \"$@\";exit $?\n\nThis self-contained script runner for Docker via:\nhttps://github.com/hugojosefson/docker-shebang\n*/\n\n```\n\nSee also [node-example.js](./node-example.js) for the full example, with code.\n\n### Node.js with npm dependencies\n\nYou can set `DOCKER_IMAGE` to any compatible Docker image with `node`. Suggested: [node](https://hub.docker.com/_/node).\n\nYou can also specify the contents of a `package.json`, which will be installed inside Docker each time your script is\nrun.\n                   \nPaste this shebang line and comment at the beginning of your `.js` script file, and edit the `dependencies` to your\nneeds:\n\n```js\n#!/usr/bin/env sh\n/* 2\u003e/dev/null\nDOCKER_IMAGE=node:lts\nDOCKER_CMD=\"node\"\n\nPACKAGE_JSON='{\n  \"dependencies\": {\n\n    // -=\u003e [ YOUR DEPS ] \u003c=- \\\\\n    // -=\u003e [  GO HERE  ] \u003c=- \\\\\n\n  }\n}'\n\n## Optionally, un-comment one of these lines to give access to current directory, read-only or read-write:\n# DOCKER_EXTRA_ARGS=\"-w $(pwd) -u $(id -u):$(id -g) -v $(pwd):$(pwd):ro\"\n# DOCKER_EXTRA_ARGS=\"-w $(pwd) -u $(id -u):$(id -g) -v $(pwd):$(pwd):rw\"\n\ns=\"$(cd \"$(dirname \"$0\")\" \u0026\u0026 pwd)/$(basename \"$0\")\";yn=\"${s}.yarn-and-node\";echo \"(cd /tmp;yarn\u003e/dev/null 2\u003e\u00261;[ \\$? = 0 ]) \u0026\u0026 exec ${DOCKER_CMD} \\\"\\$@\\\";e=\\$?;cat yarn-error.log\u003e\u00262;exit \\$e\"\u003e\"$yn\";p=\"${s}.package.json\";echo \"${PACKAGE_JSON}\"\u003e\"$p\";docker run --rm -a stdin -a stdout -a stderr -i$([ -t 0 ] \u0026\u0026 echo t) --init -v \"$s\":\"$s\":ro -v \"$yn\":/yarn-and-node:ro -v \"$p\":/tmp/package.json:ro -e NODE_PATH=/tmp/node_modules ${DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} sh /yarn-and-node \"$s\" \"$@\";e=$?;rm -- \"$yn\" \"$p\";exit $e\n\nThis self-contained script runner for Docker via:\nhttps://github.com/hugojosefson/docker-shebang\n*/\n\n```\n\nSee also [node-example-with-dependencies.js](./node-example-with-dependencies.js) for the full example, with code.\n\n### Python\n                   \nYou can set `DOCKER_IMAGE` to any compatible Docker image with `python`. Suggested: [python](https://hub.docker.com/_/python).\n\nPaste this shebang line and string literal at the beginning of your `.py` script file:\n\n```python\n#!/usr/bin/env sh\n''':'\nDOCKER_IMAGE=python:3\nDOCKER_CMD=\"python -tt\"\n\n## Optionally, un-comment one of these lines to give access to current directory, read-only or read-write:\n# DOCKER_EXTRA_ARGS=\"-w $(pwd) -u $(id -u):$(id -g) -v $(pwd):$(pwd):ro\"\n# DOCKER_EXTRA_ARGS=\"-w $(pwd) -u $(id -u):$(id -g) -v $(pwd):$(pwd):rw\"\n\ns=\"$(cd \"$(dirname \"$0\")\" \u0026\u0026 pwd)/$(basename \"$0\")\";docker run --rm -a stdin -a stdout -a stderr -i$([ -t 0 ] \u0026\u0026 echo t) --init -v \"$s\":\"$s\":ro ${DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} ${DOCKER_CMD} \"$s\" \"$@\";exit $?\n\nThis self-contained script runner for Docker via:\nhttps://github.com/hugojosefson/docker-shebang\n'''\n\n```\n\nSee also [python-example.py](./python-example.py) for the full example, with code.\n\n### Go\n\nYou can set `DOCKER_IMAGE` to any compatible Docker image with `go`. Suggested: [golang](https://hub.docker.com/_/golang).\n\nPaste this shebang line and comment at the beginning of your `.go` script file:\n\n```golang\n#!/usr/bin/env sh\n/* 2\u003e/dev/null\nDOCKER_IMAGE=golang:alpine\nDOCKER_CMD=\"go run\"\n\n## Optionally, un-comment one of these lines to give access to current directory, read-only or read-write:\n# DOCKER_EXTRA_ARGS=\"-w $(pwd) -u $(id -u):$(id -g) -v $(pwd):$(pwd):ro\"\n# DOCKER_EXTRA_ARGS=\"-w $(pwd) -u $(id -u):$(id -g) -v $(pwd):$(pwd):rw\"\n\ns=\"$(cd \"$(dirname \"$0\")\" \u0026\u0026 pwd)/$(basename \"$0\")\";ss=\"${s}.docker-shebang.go\";awk \"x==1{print}/\\*\\/$/{x=1}\" \"$0\"\u003e\"$ss\";docker run --rm -a stdin -a stdout -a stderr -i$([ -t 0 ] \u0026\u0026 echo t) --init -v \"$ss\":\"$s\":ro ${DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} ${DOCKER_CMD} \"$s\" \"$@\";e=$?;rm -- \"$ss\";exit $e\n\nThis self-contained script runner for Docker via:\nhttps://github.com/hugojosefson/docker-shebang\n*/\n\n```\n\nSee also [golang-example.go](./golang-example.go) for the full example, with code.\n\n\n### Rust\n\nYou can set `DOCKER_IMAGE` to any compatible Docker image with `cargo`. Suggested: [rust](https://hub.docker.com/_/rust).\n\nPaste this shebang line and comment at the beginning of your `.rs` script file:\n\n```rust\n#!/usr/bin/env sh\n/* 2\u003e/dev/null\nDOCKER_IMAGE=rust:1\nARGS=\"$@\"\n\n## Optionally, un-comment one of these lines to give access to current directory, read-only or read-write:\n# DOCKER_EXTRA_ARGS=\"-w $(pwd) -u $(id -u):$(id -g) -v $(pwd):$(pwd):ro\"\n# DOCKER_EXTRA_ARGS=\"-w $(pwd) -u $(id -u):$(id -g) -v $(pwd):$(pwd):rw\"\n\ns=\"$(cd \"$(dirname \"$0\")\" \u0026\u0026 pwd)/$(basename \"$0\")\";ss=\"${s}.docker-shebang.rs\";awk \"x==1{print}/\\*\\/$/{x=1}\" \"$0\"\u003e\"$ss\";docker run --rm -a stdin -a stdout -a stderr -i$([ -t 0 ] \u0026\u0026 echo t) -v \"$ss\":\"/main.rs\":ro --init ${DOCKER_EXTRA_ARGS} ${DOCKER_IMAGE} sh -c \"cd / \u0026\u0026 USER=root cargo new -q --bin app \u0026\u0026 cd app \u0026\u0026 cp ../main.rs src/ \u0026\u0026 cargo run -q --release -- ${ARGS}\";e=$?;rm -- \"$ss\";exit $e\n\nThis self-contained script runner for Docker via:\nhttps://github.com/hugojosefson/docker-shebang\n*/\n\n```\n\nSee also [rust-example.rs](./rust-example.rs) for the full example, with code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugojosefson%2Fdocker-shebang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhugojosefson%2Fdocker-shebang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugojosefson%2Fdocker-shebang/lists"}