diff --git a/action.yml b/action.yml index 7edd326..37b8127 100644 --- a/action.yml +++ b/action.yml @@ -36,14 +36,19 @@ runs: - name: Start BuildKit container (with labels) shell: bash run: | - docker ps -a --format '{{.Names}}' | grep -qx '${{ inputs.container_name }}' || \ - docker run -d --name ${{ inputs.container_name }} --privileged \ - --network ${{ inputs.network }} \ - -p 127.0.0.1:${{ inputs.port }}:${{ inputs.port }} \ - --restart unless-stopped \ - --label com.centurylinklabs.watchtower.monitor-only=${{ inputs.monitor_only }} \ - --label dockhand.notify=${{ inputs.dockhand_notify }} \ - ${{ inputs.image }} --addr tcp://0.0.0.0:${{ inputs.port }} + # Recreate if a stopped/old container exists (config drift, e.g. port + # mapping changes, would otherwise be skipped by the name guard). + # If it is already running with the right config, keep it (warm cache). + if [ "$(docker inspect -f '{{.State.Running}}' ${{ inputs.container_name }} 2>/dev/null)" != "true" ]; then + docker rm -f ${{ inputs.container_name }} >/dev/null 2>&1 || true + docker run -d --name ${{ inputs.container_name }} --privileged \ + --network ${{ inputs.network }} \ + -p 127.0.0.1:${{ inputs.port }}:${{ inputs.port }} \ + --restart unless-stopped \ + --label com.centurylinklabs.watchtower.monitor-only=${{ inputs.monitor_only }} \ + --label dockhand.notify=${{ inputs.dockhand_notify }} \ + ${{ inputs.image }} --addr tcp://0.0.0.0:${{ inputs.port }} + fi - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4