第一次使用 docker 用户,我正在使用此图像:https://github.com/dgraziotin/osx-docker-lamp
我想让该容器中的 apache 使用来自主机系统的配置文件。我该怎么做?
我知道我可以使用 nsenter
,但我认为我的更改会在容器关闭时被删除。
谢谢
最佳答案
最好的解决方案是使用 VOLUME。
docker pull dgraziotin/lamp
您需要将 /etc/apache2/
从容器复制到主机的当前目录。然后你可以这样做:
cd ~
mkdir conf
docker run -i -t --rm -v ~/conf:/tmp/conf dgraziotin/lamp:latest /bin/bash
在容器上做:
ls /tmp/conf
cd /etc/apache2/
tar -cf /tmp/conf/apache-conf.tar *
exit
在主机上:
cd conf
tar -xf apache-conf.tar
cd ..
# alter your configuration in this file and save
vi conf/apache2.conf
# run your container : daemon mode
docker run -d -p 9180:80 --name web-01 -v ~/conf:/etc/apache2 dgraziotin/lamp:latest
docker ps
列出容器使用的conf内容:
docker exec web-01 ls -lAt /etc/apache2/
total 72
-rw-r--r-- 1 root root 1779 Jul 17 20:24 envvars
drwxr-xr-x 2 root root 4096 Apr 10 11:46 mods-enabled
drwxr-xr-x 2 root root 4096 Apr 10 11:45 sites-available
-rw-r--r-- 1 root root 7136 Apr 10 11:45 apache2.conf
drwxr-xr-x 2 root root 4096 Apr 10 11:45 mods-available
drwxr-xr-x 2 root root 4096 Apr 10 11:44 conf-enabled
drwxr-xr-x 2 root root 4096 Apr 10 11:44 sites-enabled
drwxr-xr-x 2 root root 4096 Apr 10 11:44 conf-available
-rw-r--r-- 1 root root 320 Jan 7 2014 ports.conf
-rw-r--r-- 1 root root 31063 Jan 3 2014 magic
使用 docker exec web-01 cat/etc/apache2/apache2.conf
列出 Container 内的内容。
一个WEB页面来测试你的环境。
希望对你有所帮助。
关于docker - 在 docker 中编辑 apache 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31480556/