"docker monolith" approach helped me to switch from WSL to docker, I decided to create 1 image, that I will be useing with most of my local developed projects.
-
prepare project files (/PATH/TO/PROJECT) that would be the folder we mount from our host system.
-
prepare apache2 config for docker (/PATH/TO/WEB/ROOT/CONSIDERING/PROJECT) / /PATH/TO/APACHE_CONFIG/FODLER We will mount this configuration from host as the image should be ready to be used with many projects. In my case, I use yii2 and mount project folder to /var/www/mserver, so in the config file I use document root as /var/www/mserver/frontend/web e.t.c
-
create docker network to use predefiend ip (docker network create --subnet=172.18.0.0/16 NET_NAME) Wasn't able to find any better solution, as I am going to use name based hosting I need to have ip address to point domain's to. There was problems with reaching containers from host system (docker/for-win#221 (comment)) workaround fix:
docker network create --driver=bridge --subnet=172.28.0.0/16 --ip-range=172.28.5.0/24 --gateway=172.28.5.254 br0
route add 172.28.0.0 mask 255.255.0.0 10.0.75.2 -p
-
fill /etc/hosts to point a name to the ip from network range (ex.172.28.5.3)
command:
docker container run --name NAME
--network br0 --ip CONTAINER_IP_ADDRESS
--volume /PATH/TO/PROJECT:/var/www/mserver
--volume /PATH/TO/APACHE_CONFIG:/etc/apache2/sites-enabled/0000-main.conf
-it --rm IMAGE/NAME
final example:
docker container run --name amurazg --network br0 --ip 172.28.5.3 --volume /c/arsen/mserver/consideration/amurazg.com:/var/www/mserver --volume /c/arsen/configd/docker/amurazg/dev.amurazg.com.conf:/etc/apache2/sites-enabled/0000-main.conf -it --rm anga/ubuntu
note: again here we have to restart apache for mounted config to take effect
As we yet want to use docker only for develepment environment, we can use docker commits to not maintain docker files
docker commit -m "COMMIT MESSAGE" CONTAINER_ID IMAGE/NAME:TAG
ex:
docker commit -m "apache mods" 434342540ecb anga/ubuntu:latest
When image with project is ready, we may want to setup mysql/phpmyadmin containers. Note that I have to setup ip addresses from the same network to work with
docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
ex:
docker run --name amurazgdb --network br0 --ip 172.28.5.4 -v /c/arsen/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=manag -d mysql
docker run --name myadmin -d --network br0 --ip 172.28.5.5 -p 8180:80 -e MYSQL_ROOT_PASSWORD=manag -e PMA_HOST=172.28.5.4 phpmyadmin/phpmyadmin
WARNING:
- this is not a reccommended way to use docker probably, but it still helped me with my development environment, so I decided to write up the steps for further refference and in case if someone will find such usage useful too. Any comments and suggestions are welcome!