下面我们对应用进行一个简单的改动,将
No items yet! Add one above!
改为You have no todo items yet! Add one above!
。
更新源代码
- 在
src/static/js/app.js
文件中,更新 56 行使用下面的语句。
<p className="text-center">You have no todo items yet! Add one above!</p>
- 使用之前的语句更新镜像的版本。
docker build -t getting-started .
- 启动一个新容器
docker run -dp 3000:3000 getting-started
你可能会出现如下的错误
Bind for 0.0.0.0:3000 failed: port is already allocated.
这是因为我们启动新容器时,之前的旧容器仍在运行。而旧容器正在使用主机的 3000 端口。所以,我们需要去移除旧容器。
替换旧容器
为了移除一个容器,首先需要停止它。下面有两种方式可以去移除容器。
使用 CLI 移除容器
- 使用
docker ps
命令获取容器的 ID
docker ps
- 使用
docker stop
命令停止容器
Swap out <the-container-id> with the ID from docker ps
docker stop <the-container-id>
- 然后你就可以使用
docker rm
移除容器
docker rm <the-container-id>
你可以停止并移除容器,使用
docker rm -f <the-container-id>
使用 Docker 面板移除容器
如果你打开 Docker 面板,你可以通过点击移除容器。
启动被更新的应用容器
- 启动被更新的应用
docker run -dp 3000:3000 getting-started
- 刷新浏览器,在 http://localhost:3000/,然后你会看到被更新的文本。