docker - 在 docker 中编辑 apache 配置

标签 docker

第一次使用 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/

相关文章:

docker - 如何将 Mysql docker 容器连接到 Grafana

ruby-on-rails - 添加除 Dockerfile 之外的项目文件夹

linux - 如何从 Amazon Linux AMI 创建 docker 基础镜像

mysql - 未知的 MySQL 服务器主机 'db' Rails 和 Docker

php - 无法从 php 容器连接到 mysql 容器

docker - 如何在收集的帮助下从uwsgi收集指标

django - 创建 dockerfile 以构建新图像

docker - 运行在 Docker 中的 Minikube,以及端口转发

php - 将 mbstring 添加到 laravel 5 应用程序的 docker 图像

tomcat - 无法在浏览器 [docker] 中公开端口以从本地主机访问网络服务器