Update the applicationアプリケーションを更新する
In part 1, you containerized a todo application. In this part, you'll update the application and image. You'll also learn how to stop and remove a container.前のパート 1では、todoアプリケーションをコンテナ化しました。このパートでは、アプリケーションとイメージを更新します。また、コンテナを停止して削除する方法も学びます。
Update the source codeソースコードを更新する
In the following steps, you'll change the "empty text" when you don't have any todo list items to "You have no todo items yet! Add one above!"次のステップでは、todoリストアイテムがないときの「空のテキスト」を「まだtodoアイテムがありません!上に追加してください!」に変更します。
In the
src/static/js/app.jsfile, update line 56 to use the new empty text.ファイルsrc/static/js/app.jsの56行目を更新して、新しい空のテキストを使用します。- <p className="text-center">No items yet! Add one above!</p> + <p className="text-center">You have no todo items yet! Add one above!</p>Build your updated version of the image, using the
docker buildcommand.更新されたバージョンのイメージを、docker buildコマンドを使用してビルドします。$ docker build -t getting-started .Start a new container using the updated code.更新されたコードを使用して新しいコンテナを開始します。
$ docker run -dp 127.0.0.1:3000:3000 getting-started
You probably saw an error like this:おそらく、次のようなエラーを見たでしょう:
docker: Error response from daemon: driver failed programming external connectivity on endpoint laughing_burnell
(bb242b2ca4d67eba76e79474fb36bb5125708ebdabd7f45c8eaf16caaabde9dd): Bind for 127.0.0.1:3000 failed: port is already allocated.
The error occurred because you aren't able to start the new container while your old container is still running. The reason is that the old container is already using the host's port 3000 and only one process on the machine (containers included) can listen to a specific port. To fix this, you need to remove the old container.このエラーは、古いコンテナがまだ実行中のため、新しいコンテナを開始できないことが原因です。理由は、古いコンテナがすでにホストのポート3000を使用しており、マシン上の特定のポートをリッスンできるプロセスは1つだけ(コンテナを含む)だからです。これを修正するには、古いコンテナを削除する必要があります。
Remove the old container古いコンテナを削除する
To remove a container, you first need to stop it. Once it has stopped, you can remove it. You can remove the old container using the CLI or Docker Desktop's graphical interface. Choose the option that you're most comfortable with.コンテナを削除するには、まずそれを停止する必要があります。停止したら、削除できます。CLIまたはDocker Desktopのグラフィカルインターフェースを使用して古いコンテナを削除できます。自分が最も快適に感じるオプションを選んでください。
Remove a container using the CLICLIを使用してコンテナを削除する
Get the ID of the container by using the
docker pscommand.docker psコマンドを使用してコンテナのIDを取得します。$ docker psUse the
docker stopcommand to stop the container. Replace<the-container-id>with the ID fromdocker ps.docker stopコマンドを使用してコンテナを停止します。<the-container-id>をdocker psからのIDに置き換えます。$ docker stop <the-container-id>Once the container has stopped, you can remove it by using the
docker rmcommand.コンテナが停止したら、docker rmコマンドを使用して削除できます。$ docker rm <the-container-id>
NoteYou can stop and remove a container in a single command by adding the
forceflag to thedocker rmcommand. For example:docker rm -f <the-container-id>コンテナを停止して削除するには、docker rmコマンドにforceフラグを追加することで、1つのコマンドで実行できます。例えば:docker rm -f <the-container-id>
Remove a container using Docker DesktopDocker Desktopを使用してコンテナを削除する
- Open Docker Desktop to the Containers view.Docker Desktopをコンテナビューで開きます。
- Select the trash can icon under the Actions column for the container that you want to delete.削除したいコンテナのアクション列のゴミ箱アイコンを選択します。
- In the confirmation dialog, select Delete forever.確認ダイアログで、永久に削除を選択します。
Start the updated app container更新されたアプリコンテナを起動する
Now, start your updated app using the
docker runcommand.次に、docker runコマンドを使用して更新されたアプリを起動します。$ docker run -dp 127.0.0.1:3000:3000 getting-startedRefresh your browser on http://localhost:3000 and you should see your updated help text.http://localhost:3000 でブラウザをリフレッシュすると、更新されたヘルプテキストが表示されるはずです。
Summary概要
In this section, you learned how to update and rebuild an image, as well as how to stop and remove a container.このセクションでは、イメージの更新と再構築、コンテナの停止と削除の方法を学びました。
Related information:関連情報:
Next steps次のステップ
Next, you'll learn how to share images with others.次に、他の人とイメージを共有する方法を学びます。
Share the application