Use Kompose to convert docker-compose.yaml but got an error decoding 'Ports': No port specified: :: <empty>


Today (2019/Sep/12), I needed to convert our docker-compose.yaml to Kubernetes YAML files for saving my life. My colleague suggested me to use Kompose (1.18.0) to do the conversions.

But unfortunately, after I executed the following command,
$ kompose convert -v -f docker-compose.yaml
the bad luck messages were coming out,
DEBU Checking validation of provider: kubernetes
DEBU Checking validation of controller:
DEBU Docker Compose version: 3
FATA 1 error(s) decoding:

* error decoding 'Ports': No port specified: :: <empty>
I noticed the problem should be related to "(Environment) Variables". Because the values of variables in .env file were not passed to Kompose and the error wouldn't happen when I used constants. Even though there are many PRs, like this one,
error decoding 'Ports': No port specified: ::<empty> #1104
or these,
Fixes .env file lookup #448
v3 env substitution is not working #650  
Or more, they didn't fix the issue I had.

To be honest, I only check 3-5 source files at that moment since I needed a quick solution for our tasks and to escape from this issue.

Then, I think if I can load the .env file and output it to a temp file. That will be perfect! I googled it and here are we go: docker-compose config (I got this from a PR but I can't find it anymore. Sorry about it.) The concept of the command below is: the variables will be transformed to values and will be saved as a new docker-compose.yaml file,
$ docker-compose config > ./k8s/docker-compose.yaml
Then, to walk into the ./k8s directory and execute the first command again,
$ kompose convert -v -f docker-compose.yaml
We can live happily ever after. Done.

留言