使用 composerize 指令將 docker run 指令轉成 docker-compose

若想要把 docker run 轉成 docker-compose 做法如下:

composerize

安裝 npm 然後再裝 composerize cli 

npm install composerize -g to install, and run as such

composerize docker <span class="hljs-built_in"><span class="hljs-built_in"><span class="hljs-built_in">run</span></span></span> -p <span class="hljs-number"><span class="hljs-number"><span class="hljs-number">80</span></span></span>:<span class="hljs-number"><span class="hljs-number"><span class="hljs-number">80</span></span></span> -v /var/<span class="hljs-built_in"><span class="hljs-built_in"><span class="hljs-built_in">run</span></span></span>/docker.sock:/tmp/docker.sock:ro --restart always --log-opt <span class="hljs-built_in"><span class="hljs-built_in"><span class="hljs-built_in">max</span></span></span>-<span class="hljs-built_in"><span class="hljs-built_in"><span class="hljs-built_in">size</span></span></span>=<span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span>g nginx

產生結果如下:

<span class="hljs-attr"><span class="hljs-attr">version:</span></span> <span class="hljs-string"><span class="hljs-string">'3.3'</span></span>
<span class="hljs-attr"><span class="hljs-attr">services:</span></span>
<span class="hljs-attr"><span class="hljs-attr">    nginx:</span></span>
<span class="hljs-attr"><span class="hljs-attr">        ports:</span></span>
<span class="hljs-bullet"><span class="hljs-bullet">            -</span></span> <span class="hljs-string"><span class="hljs-string">'80:80'</span></span>
<span class="hljs-attr"><span class="hljs-attr">        volumes:</span></span>
<span class="hljs-bullet"><span class="hljs-bullet">            -</span></span> <span class="hljs-string"><span class="hljs-string">'/var/run/docker.sock:/tmp/docker.sock:ro'</span></span>
<span class="hljs-attr"><span class="hljs-attr">        restart:</span></span> <span class="hljs-string"><span class="hljs-string">always</span></span>
<span class="hljs-attr"><span class="hljs-attr">        logging:</span></span>
<span class="hljs-attr"><span class="hljs-attr">            options:</span></span>
<span class="hljs-attr"><span class="hljs-attr">                max-size:</span></span> <span class="hljs-number"><span class="hljs-number">1</span></span><span class="hljs-string"><span class="hljs-string">g</span></span>
<span class="hljs-attr"><span class="hljs-attr">        image:</span></span> <span class="hljs-string"><span class="hljs-string">nginx</span></span>