Sam
Sam

Reputation: 5657

What is the proper way to start a container after it has exited?

I have a container called sqlcontainer1. The image is "microsoft/mssql-server-linux:2017-latest". I restored a .bak file to it and now I can use it for local development. And I can even see if from SSMS (SQL Server Management Studio). Great!

The problem is after I reboot it the container status says "Exited".

The only way I can see to restart is to type:

docker start -ai sqlcontainer1

Then no command prompt is ever returned so I have to open another command prompt and retype:

docker ps -a

to see the status is now "UP 7 minutes". OK, I'm glad it's up and I can now connect back with SSMS and work from there (although I am wondering why it says 7 minutes. I've only had it up seconds). Good.

But there has to be a better way. I just want two commands like this;

docker start containerName
docker stop containerName

Is there anything like this?

If I can get that far then I would like to look into a proper restart policy.

Upvotes: 0

Views: 171

Answers (1)

Samarek
Samarek

Reputation: 444

You can set a container to restart=always when you create it or afterwards you can update it with

docker update --restart=always <container>

Then the container will always run on startup of your computer

Upvotes: 1

Related Questions