Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit a file in docker container from outside the container?

Tags:

docker

I have one docker container, that container is running in weblogic11 so that Weblogic is running by default in Production-mode, so I want to change that production-mode to Development-mode, for that I need to edit file config.xml inside the container, how we can edit that file from outside the container?

like image 897
hareesh n Avatar asked Nov 02 '25 03:11

hareesh n


2 Answers

You can do this by mounting your volumes. E.g

services:
    web:
        image: your_image:tag
        volumes:
          - app_config:/locaiton_of_config_folder

volumes:
  app_config:

This will create docker volumes and it will be mounted at /var/lib/docker/volumes/volume_name/_data and you can edit the files. Be sure to use sudo because the files are created by root user inside docker.

You can check the list of volumes by docker volume ls.

like image 166
Sivakumar Avatar answered Nov 04 '25 19:11

Sivakumar


There is one quite simple workaround to doing that.

You want to copy out the file from the running container:

docker cp <container_id>:/path/to/file .

You could edit the file with whatever you want, and you just should copy it back:

docker cp file <container_id>:/path/to/file

Optional: if you want your file to be persisted, you just need to commit the changes:

docker commit <container_id> <new_image_name>
like image 33
Mikopet Avatar answered Nov 04 '25 19:11

Mikopet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!