Reputation: 1276
I am trying to build a structure like this:
application-1/
├── docker/
│ ├── apache2
│ ├── php
│ ├── docker-compose.yml
├── src/
└── other-framework-files/
application-2/
├── docker/
│ ├── apache2
│ ├── php
│ ├── docker-compose.yml
├── src/
└── other-framework-files/
Where each application is a completely independent instance of the same code. I want to get to the point where I can have my application spawn up twice and where I can develop on two "boxes" independently.
This structure works fine for one instance.
Let's just say that in my folder I have only one app which I run with:
cd application-1/
docker-compose up -d
This is my docker-compose.yml file
version: '3.7'
services:
webapp:
build:
context: ./php/
dockerfile: Dockerfile
container_name: webapp
image: php:7.4.2-fpm-alpine
volumes:
- ../:/srv/app
apache2:
build:
network: host
context: ./apache2/
dockerfile: Dockerfile
container_name: apache2
image: httpd:2.4.39-alpine
ports:
- 8080:80
volumes:
- ../:/srv/app
mysql:
container_name: mysql
image: mysql:latest
ports:
- 13306:3306
volumes:
- mysql:/var/lib/mysql:cached
environment:
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: content
MYSQL_USER: content
MYSQL_PASSWORD: content
redis:
container_name: redis
image: redis:5.0.6-alpine
ports:
- 16379:6379
volumes:
- redis:/data:cached
volumes:
mysql:
driver: local
redis:
driver: local
This WORKS perfectly fine for one instance of the app.
When I go to
http://123.123.123:8080 (my Digital Ocean droplet)
I can see my website and it's all good.
However, if I want to copy that over to application 2 and run it from there I can't get that to work. For the second application I have tried to change the name of all the containers and I also changed ports like this:
version: '3.7'
services:
webapp2:
build:
context: ./php/
dockerfile: Dockerfile
container_name: webapp2
image: php:7.4.2-fpm-alpine
volumes:
- ../:/srv/app
apache2-2:
build:
network: host
context: ./apache2/
dockerfile: Dockerfile
container_name: apache2-2
image: httpd:2.4.39-alpine
ports:
- 8081:80
volumes:
- ../:/srv/app
mysql2:
container_name: mysql2
image: mysql:latest
ports:
- 13309:3306
volumes:
- mysql:/var/lib/mysql:cached
environment:
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: content
MYSQL_USER: content
MYSQL_PASSWORD: content
redis2:
container_name: redis2
image: redis:5.0.6-alpine
ports:
- 16380:6379
volumes:
- redis:/data:cached
volumes:
mysql2:
driver: local
redis2:
driver: local
By doing this I was hoping I could get two COMPLETELY independent multi-container composer apps. So that two developers could work separately on the same app.
But when I try to access it like this
http://123.123.123:8081
It just doesn't load anything. Says the website is unavailable. It doesn't hit apache or anything. It just doesn't work.
Would anyone be able to point me into the right direction here? I do not need any fancy solutions. It is just for the development, just to get started and then I can try to tweak stuff.
UPDATE:
This is my apache2 config. I have changed webapp to webapp2 for second instance.
LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so
LoadModule rewrite_module modules/mod_rewrite.so
<VirtualHost *:80>
ServerName www.content.local
ServerAlias content.local
# Proxy .php requests to port 9000 of the php-fpm container
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://webapp:9000/srv/app/public/$1
DocumentRoot /srv/app/public
<Directory /srv/app/public>
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Send apache logs to stdout and stderr
CustomLog /proc/self/fd/1 common
ErrorLog /proc/self/fd/2
</VirtualHost>
Upvotes: 0
Views: 816
Reputation: 2061
Most important thing, you don't actually need to rename anything except for the external (host) ports and should be able to reuse same docker-compose file by using namespacing. Namespacing is achieved via --project-name (or -p) flag in compose. And compose command with it would be done as following:
docker-compose -p customprojectname1 up -d
Here your customprojectname1 essentially establishes namespace - change it to something else for your 2nd instance etc. Again, you would still have to change host ports, as those would conflict, but nothing else should.
Regarding, your original solution with renaming everything - most likely your issue is with volumes that you forgot to rename in v2:
i.e. for mysql you have mount point set to mysql below:
mysql2:
container_name: mysql2
image: mysql:latest
ports:
- 13309:3306
volumes:
- mysql:/var/lib/mysql:cached
Which is your old mysql volume - from old stack (not renamed). Same with redis. So it needs to be mysql2 and redis2. Again, rather than doing that, go with namespacing solution I mentioned above.
Last thing, make sure to check container logs for each of the spawned containers in case they would have more clues.
Upvotes: 1