Change apache configuration in docker

The first user is docker here, I use this image: https://github.com/dgraziotin/osx-docker-lamp

I want to make apache in this container to use the configuration file from the host system. How to do it?

I know what I can use nsenter, but I think that my changes will be deleted when the container is turned off.

thank

+4
source share
2 answers

The best solution is to use VOLUME.

docker pull dgraziotin/lamp

You need to copy /etc/apache2/from the container to the current directory on the host computer. Then you can do this:

cd ~
mkdir conf 
docker run -i -t --rm -v ~/conf:/tmp/conf  dgraziotin/lamp:latest /bin/bash

In container:

ls /tmp/conf
cd /etc/apache2/ 
tar -cf /tmp/conf/apache-conf.tar *
exit

On the host computer:

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

To display the contents of a Context when using a container:

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 .

WEB .

, .

+6

Dockerfile , . :

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

, my-config-file, , Dockerfile. :

docker build -t myimage

, myimage, .

+3

Source: https://habr.com/ru/post/1598409/


All Articles