Issue
So I have an app deployed with docker but I'm tired to delete and rebuild the image everytime so i used wrote a script to do everything for me:
#!/usr/bin/env sh
docker-compose ps # lists all services (id, name)
docker-compose stop dee506ab283a #this will stop only the selected container
docker-compose rm dee506ab283a # this will remove the docker container permanently
docker-compose up
The problem is that the container wont have the same id everytime so this only works once. How can I get the new generated id so I can just run this script everytime?
Solution
Add a container_name
to the service in your docker-compose.yml
file like so:
services:
...
postgres:
container_name: my-container
image: postgres:12.1-alpine
...
Then you can use the following docker
commands to do what you're looking for:
docker-compose ps
docker stop my-container
docker rm my-container
docker-compose up
Answered By - Ryan Cahill Answer Checked By - Robin (WPSolving Admin)