第一次停靠用户在这里,我正在使用这个图像:https://github.com/dgraziotin/osx-docker-lamp
我想在该容器中使用apache来使用来自主机系统的配置文件.我怎么做?
我知道我可以使用nsenter,但我认为当容器关闭时我的更改将被删除.
谢谢
最好的解决方案是使用VOLUME.
docker pull dgraziotin/lamp
Run Code Online (Sandbox Code Playgroud)
您需要/etc/apache2/从容器复制到主机中的当前目录.然后你可以这样做:
cd ~
mkdir conf
docker run -i -t --rm -v ~/conf:/tmp/conf dgraziotin/lamp:latest /bin/bash
Run Code Online (Sandbox Code Playgroud)
在容器上:
ls /tmp/conf
cd /etc/apache2/
tar -cf /tmp/conf/apache-conf.tar *
exit
Run Code Online (Sandbox Code Playgroud)
在主机上:
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
Run Code Online (Sandbox Code Playgroud)
列出容器使用的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
Run Code Online (Sandbox Code Playgroud)
使用docker exec web-01 cat /etc/apache2/apache2.conf列出集装箱内部的内容.
一个用于测试环境的WEB页面.
我希望这对你有帮助.
您应该使用 aDockerfile生成包含所需配置的新图像。例如:
FROM dgraziotin/lamp
COPY my-config-file /some/configuration/file
Run Code Online (Sandbox Code Playgroud)
这假设有一个文件my-config-file与Dockerfile. 然后运行:
docker build -t myimage
Run Code Online (Sandbox Code Playgroud)
一旦构建完成,您将拥有一个名为myimage可用本地的图像。
| 归档时间: |
|
| 查看次数: |
12664 次 |
| 最近记录: |