We currently have docker containers with complex builds using supervisord so that we can group services together. For example, nginx and ssh.
I'm attempting to rebuild these with more service-driven isolation linked by shared volumes. However, without mapping the IP to the host, I can't seem to find a way to allow IP addresses to be shared even though the ports may be discrete.
What I'm trying to do is something like this:
version: '2'
services:
web:
image: nginx
volumes:
- /data/web:/var/www
networks:
public:
ipv4_address: 10.0.0.1
ports:
- "10.0.0.1:80:80"
ssh:
image: alpine-sshd
volumes:
- /data/web:/var/www
networks:
public:
ipv4_address: 10.0.0.1
ports:
- "10.0.0.1:22:22"
networks:
public:
external: true
...where public
is a predefined docker macvlan network.
When I try this, I get the error:
ERROR: for ssh Cannot start service ssh: Address already in use
I'm aware that another solution to this is to introduce a third service to work as a proxy. However, I thought this would be a simple enough case not to need it.
Is it possible to configure docker-compose/docker-networking to route by the port to allow the same IP address to be used for different containers?