03 更新应用

更新应用(删除并重建容器)

In this part, you will update the application and container image. You will also learn how to stop and remove a container.

注意:这种方式,删除容器的过程中,容器中文件的创建修改也会丢失。

更新源码

  1. 打开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>
     ...
  2. 重新编译镜像image

    docker build -t getting-started .
  3. 此时直接启动会失败

    docker run -d -p 3000:3000 getting-started

    因为原来的容器还在运行。

移除旧容器

移除旧容器之前,需要先停止容器

查看运行中的容器:(会有一串字符串,标识容器id)

docker ps

停止对应的容器:

docker stop <the-container-id>

删除对应的容器:

docker rm <the-container-id>

运行更新过的app容器

  1. 使用镜像创建并运行更新过的app

    docker run -d -p 3000:3000 getting-started
  2. 在浏览器中刷新http://<your_ip>:3000, 然后可以看到提示信息已经改变

注意

While you were able to build an update, there were two things you might have noticed:

  • All of the existing items in your todo list are gone! That’s not a very good app! You’ll fix that shortly.
  • There were a lot of steps involved for such a small change. In an upcoming section, you’ll learn how to see code updates without needing to rebuild and start a new container every time you make a change.

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注