2

用 shebang 掛起 Docker instance

 8 months ago
source link: https://blog.gslin.org/archives/2024/01/14/11593/%e7%94%a8-shebang-%e6%8e%9b%e8%b5%b7-docker-instance/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

用 shebang 掛起 Docker instance

週末偶而會看到一些奇怪的 side project,像是用 shebang (#!) 直接跑起一個 Docker instance 的方式:「Show HN: #!/usr/bin/env docker run (gist.github.com)」,程式碼在 gist 上:「adtac/595b5823ef73b329167b815757bbce9f」。

可以看到裡面主要的內容都是 Dockerfile,然後重點在開頭的 shebang command,把這些 Dockerfile 的指令倒進去跑 docker build:

#!/usr/bin/env -S bash -c "docker run -p 8080:8080 -it --rm \$(docker build --progress plain -f \$0 . 2>&1 | tee /dev/stderr | grep -oP 'sha256:[0-9a-f]*')"

記得這邊處理後面參數的部分有 undefined behavior,在 id=38989173 這邊也有人提到了:

Beware of portability: it relies on a non-standard behavior from some operating systems. It only works on OSs that treat all the text after the first space as argument(s) to the shebanged executable; rather than just treating the whole string as an executable path (that can happen to contain spaces).

但這主要是好玩,也就還好了...

Related

使用 heredoc 語法的 Dockerfile

在 Simon Willison 這邊看到的,在 Dockerfile 裡面使用 heredoc 語法編 Docker image:「Introduction to heredocs in Dockerfiles」,引用的文章是「Introduction to heredocs in Dockerfiles」與「Introduction to heredocs in Dockerfiles」,七月的事情了。 heredoc 指的是可以讓開發者很方便使用多行結構,在 Dockerfile 這邊常見到的 pattern: RUN apt-get update RUN apt-get upgrade -y RUN apt-get install -y ... 但這樣會產生出很多層 image,所以先前的 best practice 是: RUN apt-get update && \ apt-get…

November 24, 2021

In "Computer"

在 Docker 裡面跑 GUI 程式

由於想把一些東西隔離放到 Docker 裡跑,所以找了些資料看看怎麼做。 在「Running GUI apps with Docker」這邊講了怎麼在 Docker 裡面跑 Firefox,不過在我的電腦上有狀況 (跑起來沒問題,但開網頁後 Firefox 就會 crash),也許再找時間看看吧... 不過這邊學到了把 X11 的相關資源丟進去的方式: docker run -ti --rm \ -e DISPLAY=$DISPLAY \ -v /tmp/.X11-unix:/tmp/.X11-unix \ firefox 不過畢竟是把整個 X11 資源都暴露進去了,技術上並不安全,只能跑一些大公司的程式,這些公司至少不能明目張膽的把 screenshot 一直傳回去... (還是其實都有做?@_@) 另外是 Skype,之前在「用 Docker 跑 Skype 講電話」這邊就有提過了。而另外一個是「tomparys/docker-skype-pulseaudio」。但之前發現中文字型都還是有問題,也續要看看他們的 Dockerfile 怎麼寫,然後自己再改一下,把中文的部份包進去... 然後是 Dropbox,在經過「Dropbox Responds to Mac 'Security…

December 11, 2016

In "Computer"

在 Fly.io 上面跑 PHP

在 Heroku 把 free tier 拔的差不多後 (「Heroku 公佈了廢止免費方案的時間表」、「Heroku 的替代方案」),大家手上的小專案都往其他的服務跑,目前看起來做的比較有規模的就是 Fly.io 了,一個人可以建很多個 organization,而每個 organization 都有 free quota 可以用... Fly.io 官方的文件 FLy.io Docs 裡面可以看到說明,介紹怎麼把 Laravel 站台跑起來,不過沒介紹怎麼跑純 PHP 站台,所以就看了文件研究看看,發現可以用 Docker container 跑,那就簡單了。 專案放在 GitHub 的 gslin/fly-vanilla-php 上面。 一開始我的 Fly App 用的是 V1 的版本,是跑起來了,但後來還是換到 V2 跑,雖然兩者用起來沒有太大區別 (參考「Fly Apps」這邊的說明),但畢竟官方打算都把 V1 掛上 legacy 了,新的專案就儘量別用了... 另外一開始用 buildpacks…

May 16, 2023

In "Cloud"

a611ee8db44c8d03a20edf0bf5a71d80?s=49&d=identicon&r=gAuthor Gea-Suan LinPosted on January 14, 2024January 14, 2024Categories Computer, Murmuring, SoftwareTags docker, dockerfile, image, instance, shebang, unix

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Learn More)

Post navigation


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK