Docker の紹介
Tim Sangster
Software Engineer @ DataCamp
hello-world イメージはテキストを出力してから停止します。
docker run hello-world
Hello from Docker!
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon created a new container from the hello-world image which runs the
executable that produces the output you are currently reading.
3. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
Pythonを含むイメージは起動時にPythonを開始できます。
docker run python3-sandbox
Python 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
...
....
>>> exit()
repl@host:/#
CMD <shell-command>
CMD命令:
ワークフローを実行する、または外部接続を受け入れるアプリケーションの開始。
CMD python3 my_pipeline.py
CMD postgres
複数のアプリケーションを起動するスクリプトの開始
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
より一般的なイメージには、より一般的な開始コマンドが必要です。
イメージの起動
docker run <image>
カスタム起動コマンドを使用したイメージの起動
docker run <image> <shell-command>
カスタム起動コマンドを使用したイメージのインタラクティブな起動
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| 使用法 | Dockerfile 命令 |
|---|---|
| イメージからコンテナが起動されたときに実行するシェルコマンドを追加します。 | CMD <shell-command> |
| 使用方法 | シェルコマンド |
|---|---|
| イメージ内で設定された CMD を上書きする | docker run <image> <shell-command> |
| 画像内で設定された CMD を上書きし、対話形式で実行する | docker run -it <image> <shell-command> |
Docker の紹介