Attach to running container on docker-compose and restart binary

I’m using docker-compose to make the interaction of my c++ binary with mongodb. Since the binary is mounted at the container through a volume, everytime I recompile my app, the new binary is gonna be inside the container. I need to make the container restart the program so it loads the new binary. Obviously I could just restart everything by doing control + C and then docker-compose up agaib, but this process slows down everything, as I need to wait for al the other containers to start again.

I trried to do docker attach on the container that runs the binary but it hangs forever. What should I do?

If there is a way to restart only the container that has the binary, that’s great, but it’d be even beter if I could just get inside the container and stop/re-run the binary over and over

Its not a good idea to mount the binary inside the container using volume. I would suggest putting the binary inside container and rebuilding container when binary changes. This can be done using any automated approach(github/docker hub/jenkins, docker cloud etc). When container is rebuilt and you do “docker compose up”, Docker will automatically take care of restarting only containers that changed.

I agree, but these docker containers are for development only, so I need the binary to be there as fast as possible

Container’s life time is same as process running inside container life time. I assume when you restart the binary, container already dies… thats why you might be seeing hang…

I didn’t restart, attached to the running container, and then it hangs forever