name: Docker Deploy on: [push] jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Check out repository code uses: actions/checkout@v4 - name: Build Docker Image run: | docker build -t my-local-app:latest . # - name: Remove Old Container # run: | # # Use '|| true' to force a success exit code even if the container is missing # docker stop my-running-app || true # docker rm my-running-app || true - name: Remove Old Container and Free Port run: | # 1. Stop and remove by NAME (what we had before) docker stop my-running-app || true docker rm my-running-app || true # 2. EMERGENCY: Stop any container actually using port 9002 # This finds the ID of any container bound to 9002 and kills it PORT_OWNER=$(docker ps -q --filter "publish=9002") if [ ! -z "$PORT_OWNER" ]; then docker stop $PORT_OWNER docker rm $PORT_OWNER fi - name: Start New Container run: | docker run -d \ --name my-running-app \ -p 9002:5005 \ --restart unless-stopped \ my-local-app:latest # - name: Deploy to CasaOS (Docker) # run: | # # Stop and remove the old container if it exists # docker stop my-running-app || true # docker rm my-running-app || true # # Run the new container # docker run -d \ # --name my-running-app \ # -p 9002:5005 \ # --restart always \ # my-local-app:latest