我有一个Docker容器,该容器正在运行Weblogic11,因此Weblogic默认在生产模式下运行,所以我想将该生产模式更改为开发模式,为此需要编辑容器内的config.xml
文件,我们如何从容器外部编辑该文件?
我有一个Docker容器,该容器正在运行Weblogic11,因此Weblogic默认在生产模式下运行,所以我想将该生产模式更改为开发模式,为此需要编辑容器内的config.xml
文件,我们如何从容器外部编辑该文件?
当然可以做到。有一个名为mounting
的Docker配置。要在容器内挂载文件,请在docker run
命令中添加-v参数:
docker run -d -v /path/to/your-file.xml:/path/to/file/inside/container-shoulbe.xml image:version
如果你正在使用docker-compose,那么你的docker-compose.yml
文件应该像这样:
...
services:
web:
image: xxx:version
volumes:
...
- /path/to/your-file.xml:/path/to/file/inside/container-shoulbe.xml
...
docker cp <container_id>:/path/to/file .
docker cp file <container_id>:/path/to/file
可选:如果您希望将文件持久化,只需提交更改即可:
docker commit <container_id> <new_image_name>
services:
web:
image: your_image:tag
volumes:
- app_config:/locaiton_of_config_folder
volumes:
app_config:
/var/lib/docker/volumes/volume_name/_data
上,您可以编辑文件。请确保使用sudo
,因为文件是由Docker内部的root用户创建的。您可以通过docker volume ls
检查卷列表。docker exec -it container_id bash
然后 vi /path/to/config.xml
,nano /path/to/config.xml
,.... 如果你想编辑文件。
然后重新启动容器:
docker restart container_id