Hello,
I have an application where the UI connects to the backend on udp port. When i run the backend process in a standalone docker container, the UI connects fine with the backend. However, if i run the same backend container using docker-compose, UI doesn’t seem to connect to the backend. when i see standalone the container using docker container ls, i don’t see any ports explicitly exposed but it works. However, i even tried to expose the ports in docker-compose, the container hosted doesn’t show connections. Any idea what could be different between running the container standalone versus with docker compose?
Please provide the exact commands you use to start your containers from the cli and your compose file. There must be a configuration difference.
I have yet to encounter a docker run command that is not expressable as a compose file and vice versa. They are just different representations of a “client-frontend” that drive the very same api endpoints of the docker engine.
The most obvious differences between your docker run and compose file are:
equivalent of --pid=host missing in compose file
equivalent of --network=host missing in compose file (uses bridge instead and published ports)
equivalent of -u $(id -u):$(id -g) missing in compose file
your comose file has a command, you docke run does not.
Let me take a look at the compose specs and fill the voids. Which is the prefered network approach? host network OR brige + published ports?
update: I reformated your post, now the -u parameter makes sense.
But, you can not run sub-commands in a compose file: so neither its $() or backtick syntax will work. As such the variables must exist in the shell before running docker-compose. Either by exporting them before or by prefixing your docker-compose command with it.
This should work(haven’t tested it though): UID=$(id -u) GID=$(id -g) docker-compose up -d
Small correction: I think you wanted to write “network_mode: host”, not just network which would work in the build section according to the documentation. i don’t know why Docker uses two different names for the same purpose in two different place. I didn’t even know I could use network: host during build until today so thanks.