Docker基础知识,如何保留已安装的软件包和已编辑的文件? [英] Docker basics, how to keep installed packages and edited files?

查看:333
本文介绍了Docker基础知识,如何保留已安装的软件包和已编辑的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否正确理解Docker?


  1. docker run -it --rm --name verdaccio -p 4873:4873 -d verdaccio / verdaccio

如果我的服务器上尚不存在verdaccio,并且在特定端口上运行它。 -d分离它,以便我可以离开终端并使其正常运行?


  1. docker exec -it --user root verdaccio / bin / sh

让ssh进入正在运行的容器。但是,如果我 rm 容器然后再次运行映像以及任何已编辑的文件,则我添加的任何apk软件包都会丢失。那么这有什么用呢?我可以保留图像中的更改吗?


  1. 当我需要编辑config.yaml时,存在于 /verdaccio/conf/config.yaml (位于容器中)中,保持此更改的唯一选择是从正在运行的实例中分离数据?还有另一种方式吗?

      V_PATH = / path / on / my / server / verdaccio; docker run -it --rm --name 
    verdaccio -p 4873:4873 \
    -v $ V_PATH / conf:/ verdaccio / conf \
    -v $ V_PATH /存储: / verdaccio /存储\
    -v $ V_PATH / plugins:/ verdaccio / plugins \
    verdaccio / verdaccio


但是此命令将抛出

 致命---无法打开配置文件/verdaccio/conf/config.yaml:ENOENT:没有此类文件或目录,请打开'/verdaccio/conf/config.yaml'


解决方案

您可以使用 docker commit 来基于



但是,更好的方法是使用 Dockerfile 来基于<$ c $构建映像c> verdaccio / verdaccio 进行必要的更改。这使该过程易于重复(例如,如果出现了新版本的基础映像)。



另一种选择是使用卷,如您已经提到的。 / p>

Do I understand Docker correctly?

  1. docker run -it --rm --name verdaccio -p 4873:4873 -d verdaccio/verdaccio

gets verdaccio if it does not exist yet on my server and runs it on a specific port. -d detaches it so I can leave the terminal and keep it running right?

  1. docker exec -it --user root verdaccio /bin/sh

lets me ssh into the running container. However whatever apk package that I add would be lost if I rm the container then run the image again, as well as any edited file. So what's the use of this? Can I keep the changes in the image?

  1. As I need to edit the config.yaml that is present in /verdaccio/conf/config.yaml (in the container), my only option to keep this changes is to detach the data from the running instance? Is there another way?

    V_PATH=/path/on/my/server/verdaccio; docker run -it --rm --name 
    verdaccio -p 4873:4873 \
    -v $V_PATH/conf:/verdaccio/conf \
    -v $V_PATH/storage:/verdaccio/storage \
    -v $V_PATH/plugins:/verdaccio/plugins \
    verdaccio/verdaccio
    

However this command would throw

fatal--- cannot open config file /verdaccio/conf/config.yaml: ENOENT: no such file or directory, open '/verdaccio/conf/config.yaml'

解决方案

You can use docker commit to build a new image based on the container.

A better approach however is to use a Dockerfile that builds an image based on verdaccio/verdaccio with the necessary changes in it. This makes the process easily repeatable (for example if a new version of the base image comes out).

A further option is the use of volumes as you already mentioned.

这篇关于Docker基础知识,如何保留已安装的软件包和已编辑的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆