Home  >  Q&A  >  body text

docker run -t -i /bin/bash 如何保存修改?

想通过 docker 的 /bin/bash 修改容器内容,commit 新的 image 。

未成功的操作流程如下:

docker run -t -i docker-wordpress-nginx /bin/bash

进入容器bash

vi /etc/nginx/sites-available/default

修改了 nginx 的 conf 文件

exit

退出容器,然后运行

docker ps

什么都没有。运行

docker images

还是原来那些 images。

请问如何保存在 docker 中 bash 所做的修改,如何 commit?

PS1:如何 commit 给新的 image 自动打上 tag latest,并且之前的 latest 作废(替代)?

PS2:假如通过修改和 commit 得到三个版本 tag v1, v2, v3,能否删除 v1, v2 保留 v3?即单独的 images 之间有关联(堆叠)关系吗?

黄舟黄舟2761 days ago838

reply all(3)I'll reply

  • 迷茫

    迷茫2017-04-21 11:21:10

    docker commit --help
    docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
    

    A1. If the commit is not tagged, it defaults to latest. If you modify the latest image and then commit without adding a tag, it will replace the original latest. Generally, you need to tag the original latest image before committing.

    A2. v1, v2, v3 are all tags you added yourself. docker rmi username/repo:v1You can delete v1this tag without affecting other tags

    At the same time, if the three tags v1, v2, and v3 are on the same image id, deleting the v1 tag will not delete the corresponding image

    reply
    0
  • 黄舟

    黄舟2017-04-21 11:21:10

    docker ps -l
    

    View the container that was "just" run!

    Then you get the container_id of the command you just ran

    docker commit 22bb071e070b docker-wordpress-nginx
    

    The default tag is latest


    If the above answers are wrong, you will encounter problems! Still trying, please give me some answers and Best Practices!

    reply
    0
  • ringa_lee

    ringa_lee2017-04-21 11:21:10

    Key combination: Ctrl+P+Q

    Press Enter to jump out of the docker container without closing it. This is the solution for now.

    http://blog.csdn.net/yangzhen...

    reply
    0
  • Cancelreply