The 2-Hour Bash Bug That Taught Me How Quoting Actually Works
Description and use
The post-receive hook in the mini‑paas project failed to stop and remove the old Docker container because $APP_NAME was not quoted, causing name conflicts. Using set -x revealed the issue, and quoting the variable fixed the redeploy cycle.
Problem
Automated redeploys failed silently because Docker stop and rm commands used the literal string "APP_NAME" instead of the variable value, causing container conflicts on subsequent pushes.
Outcome
Adding proper quoting to variable usage in Bash resolved silent redeploy failures, enabling reliable automated deployments.
Workflow
- 1. Push code to bare Git repo. 2. post-receive hook checks out code. 3. Build Docker image. 4. Stop old container with "docker stop $APP_NAME". 5. Remove old container with "docker rm $APP_NAME". 6. Run new container with "docker run -d --name myapp -p 5001:5000 myapp".
- 7. Verify deployment.
- 8. Debug failed redeploys by adding "set -x" to the hook to trace execution.
- 9. Identify that "docker stop" and "docker rm" were using literal "APP_NAME" due to missing quotes.
- 10. Fix by quoting variable: "docker stop \"$APP_NAME\"" and "docker rm \"$APP_NAME\"".
- 11. Redeploy succeeds.
- 12. Adopt "set -x" as first diagnostic step for silent failures.
Evidence
docker: Error response from daemon: Conflict. The container name "/myapp" is already in use...
+ docker stop APP_NAME + docker rm APP_NAME + docker run -d --name myapp -p 5001:5000 myapp
docker stop "\$APP_NAME" docker rm "\$APP_NAME"
- Record date: 2026-09-17T20:15:26.865Z