docker / libcompose

*Unmaintained/Deprecated* An experimental go library providing Compose-like functionality
https://godoc.org/github.com/docker/libcompose
Apache License 2.0
585 stars 191 forks source link

Repetition of ports from two different docker-compose files #473

Open surajssd opened 7 years ago

surajssd commented 7 years ago

I have two docker-compose files which are similar:

$ ll
total 12
-rw-rw-r--. 1 foo foo   80 May 29 14:27 docker-compose1.yml
-rw-rw-r--. 1 foo foo   80 May 29 14:28 docker-compose2.yml

$ diff docker-compose1.yml docker-compose2.yml

which looks like this:

$ cat docker-compose1.yml 
version: "2"

services:
  web:
    image: centos/httpd
    ports:
    - "80:80"

When fed to libcompose, while libcompose is trying to merge the info, it should detect the repetition of ports and error out, but it goes forward and merges it:

$ libcompose  -f docker-compose1.yml -f docker-compose2.yml up
WARN[0000] Note: This is an experimental alternate implementation of the Compose CLI (https://github.com/docker/compose) 
INFO[0000] [0/1] [web]: Starting                        
INFO[0000] Recreating web                               
ERRO[0001] Failed Starting web : Error response from daemon: driver failed programming external connectivity on endpoint multiple_web_1 (747ef1b25524286894a48c8946e1a77dba778fd6dd0245163c8f40e7acaba5b2): Bind for 0.0.0.0:80 failed: port is already allocated 
ERRO[0001] Failed to start: web : Error response from daemon: driver failed programming external connectivity on endpoint multiple_web_1 (747ef1b25524286894a48c8946e1a77dba778fd6dd0245163c8f40e7acaba5b2): Bind for 0.0.0.0:80 failed: port is already allocated 
Error response from daemon: driver failed programming external connectivity on endpoint multiple_web_1 (747ef1b25524286894a48c8946e1a77dba778fd6dd0245163c8f40e7acaba5b2): Bind for 0.0.0.0:80 failed: port is already allocated

This works fine on docker-compose:

$ docker-compose  -f docker-compose1.yml -f docker-compose2.yml up
Recreating multiple_web_1
Attaching to multiple_web_1
web_1  | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.21.0.2. Set the 'ServerName' directive globally to suppress this message
...

containers

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                NAMES
b98955e1a601        centos/httpd        "/run-httpd.sh"     7 seconds ago       Up 5 seconds        0.0.0.0:80->80/tcp   multiple_web_1

When the docker-compose files are like this:

$ cat docker-compose1.yml 
version: "2"

services:
  web:
    image: centos/httpd
    ports:
    - "80"

Just changed the port from "80:80" to "80".

Now starting this:

$ libcompose  -f docker-compose1.yml -f docker-compose2.yml up
WARN[0000] Note: This is an experimental alternate implementation of the Compose CLI (https://github.com/docker/compose) 
INFO[0000] [0/1] [web]: Starting                        
INFO[0000] Recreating web                               
INFO[0001] [1/1] [web]: Started                         
web_1 | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.21.0.2. Set the 'ServerName' directive globally to suppress this message
...

containers:

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                          NAMES
8ec86cfdd3c7        centos/httpd        "/run-httpd.sh"     8 seconds ago       Up 6 seconds        0.0.0.0:32776->80/tcp, 0.0.0.0:32777->80/tcp   multiple_web_1

The thing to note here is that it worked here because the same container port was exposed on two different ports on the host machine. Before it failed because it tried to map on the same port which was 80.

So the issue is solved by finding the repetition of ports in code before doing the deployment.

surajssd commented 7 years ago

With respect to port it is not giving any errors but the data is repeated as well when using list form of specifying ports! See https://github.com/kubernetes-incubator/kompose/pull/596#discussion_r116923543 for more details!