Docker Init

プロジェクトに必要な Docker 関連のスターター ファイルを自動作成します。

コンテナー内でプロジェクトを実行するのに必要なファイルでプロジェクトを初期化します。

Docker Desktop では、docker init CLI コマンドを利用できます。プロジェクト ディレクトリで docker init を実行すると、プロジェクトに適したデフォルトを使用して次のファイルが作成されます。

  • .dockerignore
  • Dockerfile
  • compose.yaml
  • README.Docker.md

docker init は、ASP.NET Core、Go、Java、Node、PHP with Apache、Python、Rust などのテンプレートをサポートしています。

オプション
オプション デフォルト 説明
--version -- init プラグインのバージョンを表示します。

実行例

docker init の基本実行

docker init を実行すると、対話形式のメニューが表示されます。

$ docker init
    
    Welcome to the Docker Init CLI!
    
    This utility will walk you through creating the following files with sensible defaults for your project:
      - .dockerignore
      - Dockerfile
      - compose.yaml
      - README.Docker.md
    
    Let's get started!
    
    ? What application platform does your project use?  [Use arrows to move, type to filter]
    > PHP with Apache - (detected) suitable for a PHP web application
      Go - suitable for a Go server application
      Java - suitable for a Java application that uses Maven and packages as an uber jar
      Python - suitable for a Python server application
      Node - suitable for a Node server application
      Rust - suitable for a Rust server application
      ASP.NET Core - suitable for an ASP.NET Core application
      Other - general purpose starting point for containerizing your application
      Don't see something you need? Let us know!
      Quit
Go を選択した場合
? What application platform does your project use? Go
? What version of Go do you want to use? 1.20
? What's the relative directory (with a leading .) of your main package? .
? What port does your server listen on? 3333

CREATED: .dockerignore
CREATED: Dockerfile
CREATED: compose.yaml
CREATED: README.Docker.md

✔ Your Docker files are ready!
Node を選択した場合
? What application platform does your project use? Node
? What version of Node do you want to use? 18
? Which package manager do you want to use? yarn
? Do you want to run "yarn run build" before starting your server? Yes
? What directory is your build output to? output
? What command do you want to use to start the app? node index.js
? What port does your server listen on? 8000

Created files...
✔ Your Docker files are ready!
Python を選択した場合
? What application platform does your project use? Python
? What version of Python do you want to use? 3.8
? What port do you want your app to listen on? 8000
? What is the command to run your app? python ./app.py

Created files...
✔ Your Docker files are ready!
Rust を選択した場合
? What application platform does your project use? Rust
? What version of Rust do you want to use? 1.70.0
? What port does your server listen on? 8000

Created files...
✔ Your Docker files are ready!

その他の言語(ASP.NET Core, PHP with Apache, Java)や汎用(Other)テンプレートも同様に対話形式で設定できます。生成されたファイルは自由に編集して、プロジェクトに合わせて調整してください。