如何将文件复制到停止的Docker容器

如何将文件复制到停止的Docker容器

问题描述:

我正在从Docker容器中运行elasticsearch.

I am running elasticsearch from within a docker container.

在为ssl配置elasticsearch并屏蔽我的elasticsearch.yml文件时,获得了非法条目,即TAB而不是space.
现在我的Docker容器无法启动并给出以下错误:

While configuring elasticsearch for ssl and shield my elasticsearch.yml file got illegal entry i.e. TAB instead of a space.
Now my docker container is not starting up and giving the following error:

{1.4.4}: Setup Failed ...
- SettingsException[Failed to load settings from [file:/elasticsearch/config/elasticsearch.yml]]
         IOException[Tabs are illegal in YAML.  Did you mean to use whitespace character instead?]
 org.elasticsearch.common.settings.SettingsException: Failed to load
 settings from [file:/elasticsearch/config/elasticsearch.yml]
         at org.elasticsearch.common.settings.ImmutableSettings$Builder.loadFromStream(ImmutableSettings.java:947)
         at org.elasticsearch.common.settings.ImmutableSettings$Builder.loadFromUrl(ImmutableSettings.java:931)
         at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareSettings(InternalSettingsPreparer.java:77)
         at org.elasticsearch.bootstrap.Bootstrap.initialSettings(Bootstrap.java:106)
         at org.elasticsearch.bootstrap.Bootstrap.main(Bootstrap.java:177)
         at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:32)
 Caused by: java.io.IOException: Tabs are illegal in YAML.  Did you
 mean to use whitespace character instead?
         at org.elasticsearch.common.settings.loader.YamlSettingsLoader.load(YamlSettingsLoader.java:44)
         at org.elasticsearch.common.settings.ImmutableSettings$Builder.loadFromStream(ImmutableSettings.java:944)
         ... 5 more

如何在不丢失数据或替换现有容器中的elasticsearch.yml文件的情况下编辑elasticsearch.yml或替换它?

How can I edit elasticsearch.yml or replace it without loosing data or replace the elasticsearch.yml file in my existing container?

您可以复制文件,然后再将其复制回容器( 即使容器已停止 )用docker cp $cont_name:/path/in/container /path/on/host复制出来,然后docker cp /path/on/host $cont_name:/path/in/container.

You can copy files out and then back into a container (even when the container is stopped) with the docker cp $cont_name:/path/in/container /path/on/host to copy out and then docker cp /path/on/host $cont_name:/path/in/container.