Docker Community Forums

Share and learn in the Docker community.

Restarting a Docker Container does not Restart the service inside of container

Hi there,

I have linux containers deployed on my windows machine.
This containers have .net core services inside of them.

I have a container with a service A that has special access to the docker hosts.
The job of this service A is to stop/start (or restart) the other services if they stop responding.

Lets say the service B stops responding.
I can detect that this service is not responding, so I stop the container of the service B.

Then I want to start the service B, so I start the container B after a few seconds, but it does not start the service B.

I tried to use restart without any luck.
I also tried to run the Bash command docker exec -it {containerName} ‘dotnet ./{serviceDll}’ inside of he container B but it does not seem to work.

Anyone has any ideas that could help me?

Thanks

Yes, when the initial command finish its execution then the container stops.

You can start a stopped container using:

docker start container_name

If you want to see the output of your command then you should add -ai options:

docker start -ai container_name

PS. there is a docker restart container_name but that is used to restart a running container - I believe that is not your case.

I think you did not understood.
I can start or restart a container without any problems. but the service that is running inside of that container does not start with the container.

So When you start/restart the container of service B from service A only that time issue occur.
If you start start service B directly from command prompt, does the serviceB start along with the container?

No, if I stop/start container B from prompt the same issue happens.
It only works if I start the container with a docker run from prompt or I run it from docker compose.

ok so first get service B working –

  1. start the container with docker run … or with docker compose.
  2. docker stop
  3. docker start
    Now check the logs using docker logs or if you have configured any log file then exec into the container and check the log file if not checked already. You will get some hint from the logs.
1 Like

That is what I have been doing for testing but not luck.
I start the services with compose.
Then I stop container b, then I start container b.
docker logs return nothing.
The service b has logging into file implemented
For testing reasons, the only thing Service b does is logging a message every 10 seconds.
But after the container gets stopped I dont get any more logging

What is the log message which being logged every 10 seconds.

I will make a little hello work solution and put it on github to show exactly what is going on

sure, let know once you are done…

HelloDockerMaster is the service that starts and stops the containers
ServiceNotResponding is the service that will be on the Stopped/Started container

The container for each service is named “-container” (you can see this on dockercompose.yml)
There is logging implemented in both solutions that goes to my machine on “D:\ContainerData\logs” (you can change this path in dockercompose.yml if you need to)

PS. This was created in Microsoft Visual Studio Community 2019

What happens if you restart with docker-compose restart?

Hi wonkabar.

Thanks for the suggestion and sorry for taking so long to respond.
Haven’t had much time to look into this.

No, that did not work either.
This is so strange :confused: