I have the following script, which creates the docker image and container as expected.
echo "password" | sudo -S docker stop /nexct-approval-service-container | xargs sudo docker rm
echo "docker build ..."
echo "password" | sudo -S docker build . -t nexct-approval-service-image:latest
echo "docker run ..."
echo "password" | sudo -S docker run -t --network=host -p 8081:8081 --name nexct-approval-service-container nexct-approval-service-image
As you can see I am creating a container and image with the following names:
nexct-approval-service-container
nexct-approval-service-image
However, what I cannot get to work is the following line:
echo "password" | sudo -S docker stop /nexct-approval-service-container | xargs sudo docker rm
My intention is to remove the container and image if it exists before I create a new one. What I am finding however, when I do sudo docker images
is that my list of images continues to grow.
Question
How can I build my images with the specific name, but stop a new one from being built each time?
More info:
As you can see, a number of images called <none>
are left below after each build.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nexct-approval-service-image latest 7359e1ff2138 21 seconds ago 557MB
<none> <none> c4f98256b401 About a minute ago 557MB
<none> <none> 908eebf0227a 2 minutes ago 557MB
<none> <none> 8b6b0cb01773 3 minutes ago 557MB
openjdk 14 cdc43cc23d2d 6 days ago 511MB