Docker stop & rm commands

I have a 3-tier Java spring web app having a client UI tier, rest api tier and a Mongodb data tier deployed as 3 separate docker containers with named links. Bamboo and Jenkins is used to manage the builds and scripts are called to package the Java binary artifacts with the docker files and issue the docker commands to build the images and run the containers. This is all set to run on Amazon Linux. Now in order for the build process to be repeatable we try to stop all containers and remove all containers except the data volume container created to manage the Mongodb data for the app. However the docker stop and docker rm commands routinely hang depending on what state the containers were left in on the previous run when the ec2 instance was shutdown. What is a clean way to manage the process. Can anyone clarify?