在docker中编辑apacheconfiguration

第一次在这里,docker用户,我使用这个形象: https : //github.com/dgraziotin/osx-docker-灯

我想让该容器中的apache使用主机系统中的configuration文件。 我怎么做?

我知道我可以使用nsenter ,但我认为当容器closures时我的更改将被删除。

谢谢

最好的解决scheme是使用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页面来testing你的环境。

我希望这可以帮助你。

您应该使用Dockerfile生成一个包含您所需configuration的新映像。 例如:

 FROM dgraziotin/lamp COPY my-config-file /some/configuration/file 

这假设有一个文件my-config-file位于与Dockerfile相同的目录中。 然后运行:

 docker build -t myimage 

一旦构build完成,您将在本地获得一个名为myimage的图像。