Docker-compose vs. docker run

I do like the basic idea of Docker. However, using it is cumbersome, at least sometimes.

docker-compose seems to offer a great opportunity to start-up a solution which is based on a set of Docker containers. It would be great if it would work in exactly the same manner as docker run. However, it does not seem to do so regarding its networking behaviour.

I have a, unfortunately rather complex solution, where I have a set of containers running. All of them using Thrift communication. Unfortunately, version 12 with no reasonable option to upgrade because it would result in refactoring the whole communication layer. Too, much work for too little time and if I had the time I would replace Thrift all together. So no bashing needed there. However, for now I’m stuck with it.

Reason to rease this issue here is my hope that somebody could give me a hint on where to find a in depth documentation on what docker-compose dose differently rather than docker run when it comes to networking and port mapping. Because what I’m saying is that I do have a show case where I can show that there IS a difference between starting a container using a .yaml file and starting the same (i.e. identical image) with docker run and identical port mapping and parameter passing to the container as the .yaml file suggests. Result is the container started with docker-compose crashes deep in the Thrift dll which the container started with docker run happily works. Ok, yes, mentioning dll means I’m using mono because the solution itself is mainly based on C# and yes .NET. Why then use Thrift? Well, was not my decision. People wanted to be language independent.

So admittingly it is a quite let’s challenging melange of technologies and probably not what you would use. However, I would really like to understand the difference between docker-compose and docker run …

Thanks for your help.

This is a good starting point:

Regarding network, the main difference is that compose by default creates custom docker networks or you can also read about it as “user-defined network” so each project is isolated from eachother. You could override it, but these user-defined networks are the recommended way even whej using docker run if you want multiole containers to communicate with eachother so you can use their container name (and compose service name in compose) as domain name to access another container’s port instead of using changable IP addresses.

Local firewalls or other security softwares like apparmor, selinux, seccomp could affect how network works and which one works.

If you share your compose file content and the docker run command, we can tell you whether both configurations are truly identical.

The docker cli and the compose plugin of the cli are merely user interfaces that create rest calls that are sent to the same docker api endpoints. I am confident to say that every docker run argument can be directly translated into a compose file configuration and vice versa.

Hi, thanks a lot for your reply. I’ll provide the information. However, it is more complicated than just a yml file and a run command because I’m using .env. I’ll prepare the information for you to look at and you can even try and produce the effect on your own because the images will be available at Docker Hub.

Use docker compose config to render the final compose file applied. Just make sure to anonymize credentials, domains and public ips.

Thanks for your comments. To make things hopefully a bit easier for you, I provide you access to the file test.zip which you should be able to download from

This is not a security breach because everything in there is meant to be open source anway on GitHub and Docker Hub.
Anyway, to do a test you only need to unzip the file test.zip and change to the folder test. In this folder, replace the “IP address” 0.0.0.0 in the file .env with the IP address of the machine on which you want to do the test. Please note: You need to replace both occurrences of 0.0.0.0.
After this you can first run (meant for CMD or PowerShell in Windows):
docker-compose --env-file=..env -f .\Launcher.yml up
and then in a new window:
docker-compose --env-file=..env -f .\CSharpAdapter.yml up
and see how the container crashes. Safest way to continue is to stop and remove the two containers.
Then start the first one again with:
docker-compose --env-file=..env -f .\Launcher.yml up
and go to the second window and do:
docker run -p 8911:8900 -it mosim01/mosim:csharpadapter 0.0.0.0 8900 8911 0.0.0.0:9009
where again you need to replace the two occurrences of 0.0.0.0 with the IP address of your local machine. Then you should see the CSharpAdapter happily registraing at the Launcher and running.
If you can explain to me, why the CSharpAdapter.yml does not start the CSharpAdapter in the same manner as the given docker run command, I would have learned something new about Docker and docker-compose.
PS: I tried docker compose config CSharpAdapter.yml
However, got the error message that no config file is available and I could not find hints on the net how such a file should look like. On the other hand, I also do not really believe in expanding the variables in the .yml files. I want to use .env as it is and for all images available at mosim01/mosim this actually works except the image for the CSharpAdapter.
Thanks for your help and efforts.

Thank you for preparing it, but to be honest I was more hoping to just see the compose file and the docker run command. Please forgive me If I am not going to look at it.

The docker run command docker run -p 8911:8900 -it mosim01/mosim:csharpadapter 0.0.0.0 8900 8911 0.0.0.0:9009 translates to this compose file:

services:
  myservice:
    image: mosim01/mosim:csharpadapter
    network_mode: bridge
    ports:
    - 8911:8900
    tty: true
    stdin_open: true
    command: 0.0.0.0 8900 8911 0.0.0.0:9009

As your docker run command didn’t have any environments, of course the translation to a compose file doesn’t have any environments as well.

Docker compose always implied the -d argument from docker run, which makes stdin_open:true and tty: true to be irrelevant, if the image is designed correct so that the entry point script starts a foreground process that keeps running, and runs as long as the container is supposed to run,

Please compare for yourself if this is really how you configured your compose file.

Hi I am running my project using docker compose file in visual studio 2022 . Project is .net framework 4.5. i am using windows docker compose file. while running visual studio docker compose the local default browser will open with the first start up container ip and i am getting the result. in docker compose file i am clearly mentions the local port to run the project if i call the local port mentioned in the compose file i did not get the result . it shoe 404 error how to correct the issue . (if port will call it does not work Container IP is call it will work)

Please, explain, how it is related to the “Docker Compose vs docker run” topic.