How to copy a file to a stopped docker container

I am running elasticsearch from a docker container.

When setting up elasticsearch for ssl and screen, my elasticsearch.yml file got an illegal entry, i.e. TAB instead of space .
Now my docker container does not start and gives 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 

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

+6
source share
4 answers

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

+5
source

There are several cases:

  • In the container, the elasticsearch.yml file is located in the volume data directory

The volume data directory is a special backend for storing data for Docker containers called vfs backend. Directories are essentially normal directories displayed on the host file system, and therefore do not provide copy-write capabilities. Mostly mapped directories are located in /var/lib/dockers/vfs/dir/{container_id} , but this is configurable. Of course, you can use docker inspect {container_name} to check the location:

 $> docker inspect my_container ..... (omitted output) "Volumes": { "/datadir": "/var/lib/docker/vfs/dir/b2479214c25cd39c901c3211ed14cb9668eef822a125ca85de81425d53c9ccee" }, 

As you can see, /datadir , which is the volume data directory in the container, maps to /var/lib/docker/vfs/dir/b2479214c25cd39c901c3211ed14cb9668eef822a125ca85de81425d53c9ccee of the host file system. In such circumstances, the answer to your question is quite simple: just copy them as regular files into the mapped host directory.

  1. The directory in the container is not a volume data directory.

Since Docker can use multiple storage backends for non-volumes, there is no simple answer to your question.

If you used AUFS as a backend, the container file system is mounted on the host file system, which is somewhat similar to the case of vfs. You can find the mapped directory in the host file system and access the files there. For more information about AUFS in Docker, see Docker and AUFS in practice .

If you use other servers, for example. devicemapper or btrfs, I think there is no easy way to access container files from the host. Perhaps you can try the @VonC method.

+2
source

replace it without data loss

Ideally, this data should be stored in a path installed from separate containers of data volume ( which do not start, they have just been created ). Thus, your main service container ( elasticsearch one) can be damaged and replaced as desired.
In this configuration (mount data from volume containers), you can restore the elasticsearch image with the new configuration file and return from there.

In your current configuration, if this data is not specified in the VOLUME declared by your Docker file, then you can do this:

  • [docker commit <stoppped_container_id>][1] newimage
  • create a Docker file using this new image and a COPY fixed configuration file
  • launch your container with a new image.
0
source

Tabs are not allowed in the YML file. You can edit it using any nano or vim or vi editor.

Replacing or editing the elasticsearch.yml file will not result in data loss.

Docker images are downloaded cropped to a minimum - therefore, the editor is not installed with the container sent. Therefore, you must install it manually.

 docker exec -it <container> bash 

and run:

 apt-get update apt-get install vim 

or use the following Docker file:

FROM confluent / postgres-bw: 0.1

 RUN ["apt-get", "update"] RUN ["apt-get", "install", "-y", "vim"] 

For more How to edit a file after the shell I am in a docker container?

0
source

All Articles