I get a "Failure detected. Cleaning up local services..." error

Hey,

I’ve run through the help docs and all works fine locally but facing an issue deploying. I’ve provisioned on Vultr with the following spec in spin.yml:

Vultr

  • name: vultr_1c_1gb_ubuntu2404
    provider: vultr
    profile_config:
    region: lhr
    plan: vc2-1c-1gb
    os: “Ubuntu 24.04 LTS x64”
    backups: true

But running spin deploy gives me the following error:

Successfully built ‘127.0.0.1:5080/dockerfile:20250127220709’ from ‘Dockerfile’…
:satellite: Getting deployment host information for “production”…

PLAY [Prepare CI environment.] *******************************************************************************************************************************

TASK [Display failure if required variables are not set.] ****************************************************************************************************
skipping: [localhost] => (item=spin_environment)
skipping: [localhost] => (item=spin_ci_folder)
skipping: [localhost]

TASK [Add hosts from manager_servers group to managers group if it exists] ***********************************************************************************
skipping: [localhost]

TASK [Validate inventory groups exist] ***********************************************************************************************************************
skipping: [localhost]

TASK [Set fact of full path to CI folder] ********************************************************************************************************************
ok: [localhost]

TASK [Set PRODUCTION_SSH_REMOTE_HOSTNAME with first manager host] ********************************************************************************************
ok: [localhost]

TASK [Set AUTHORIZED_KEYS file with sudo users’ SSH keys] ****************************************************************************************************
ok: [localhost]

PLAY [Update deploy user authorized keys.] *******************************************************************************************************************

PLAY RECAP ***************************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0

Authorized keys loaded and exported as AUTHORIZED_KEYS
:white_check_mark: Deploying to Swarm Manager: XXX.XXX.XXX.XXX
:metro: Creating SSH tunnel to Docker registry…
Enter passphrase for key ‘/Users/XXXXXXX/.ssh/id_ed25519’:
:white_check_mark: SSH tunnel created successfully
:information_source: Tunnel details:
:link: Local port: 5080
:desktop_computer: Remote host: XXX.XXX.XXX.XXX
:electric_plug: Remote port: 5080
:bust_in_silhouette: SSH user: deploy
:1234: SSH port: 22
:arrows_counterclockwise: The tunnel will forward connections from the remote port 5080 to 127.0.0.1:5080
:rocket: Deploying Docker stack…
:outbox_tray: Deploying Docker stack with compose files: docker-compose.yml docker-compose.prod.yml on XXX.XXX.XXX.XXX…
unknown flag: --detach
See ‘docker stack deploy --help’.
:x: Failure detected. Cleaning up local services…
Stopping local Docker registry…
Local Docker registry stopped.
Stopping local SSH tunnel…
Local SSH tunnel stopped.

Strange!

Your error is:

unknown flag: --detach

This references: docker stack deploy | Docker Docs

I assumed you used spin provision to create and install everything on the server?

Do you get more output when you run:

SPIN_DEBUG=true spin deploy

Hey @jaydrogers thanks for the reply! Great work on Spin by the way and really like the idea for spin share :slight_smile:

Yeah, I used spin provision like you said and have SSH’d into the server but no containers built or running. I’ve ran SPIN_DEBUG=true spin deploy but doesn’t really tell me much more. Any ideas?

+ echo '🔄 The tunnel will forward connections from the remote port 5080 to 127.0.0.1:5080'
🔄 The tunnel will forward connections from the remote port 5080 to 127.0.0.1:5080
++ ps aux
++ grep 'ssh -f -n -N -R 5080:127.0.0.1:5080'
++ grep -v grep
++ awk '{print $2}'
+ tunnel_pid=54801
+ echo '🚀 Deploying Docker stack...'
🚀 Deploying Docker stack...
+ deploy_docker_stack XXX.XXX.XXX.XXX 22
+ local manager_host=XXX.XXX.XXX.XXX
+ local ssh_port=22
+ compose_args=()
+ local compose_args
+ [[ 0 -eq 0 ]]
+ compose_files=("docker-compose.yml" "docker-compose.prod.yml")
+ for compose_file in '"${compose_files[@]}"'
+ [[ -n docker-compose.yml ]]
+ generate_md5_hashes docker-compose.yml
+ grep -q configs: docker-compose.yml
+ compose_args+=("--compose-file" "$compose_file")
+ for compose_file in '"${compose_files[@]}"'
+ [[ -n docker-compose.prod.yml ]]
+ generate_md5_hashes docker-compose.prod.yml
+ grep -q configs: docker-compose.prod.yml
+ local config_files
++ awk '/configs:/{flag=1;next}/^[^ ]/{flag=0}flag' docker-compose.prod.yml
++ grep file:
++ awk '{print $2}'
+ config_files=./.infrastructure/conf/traefik/prod/traefik.yml
+ for config_file_path in '$config_files'
+ '[' -f ./.infrastructure/conf/traefik/prod/traefik.yml ']'
+ local config_md5_hash
++ get_md5_hash ./.infrastructure/conf/traefik/prod/traefik.yml
++ local file=./.infrastructure/conf/traefik/prod/traefik.yml
++ local md5_hash=
++ [[ -f ./.infrastructure/conf/traefik/prod/traefik.yml ]]
++ command -v md5
++ awk '{ print $1 }'
+++ md5 -q ./.infrastructure/conf/traefik/prod/traefik.yml
++ md5_hash=1c8dbdc086c063d95548bad44aa0f312
++ echo 1c8dbdc086c063d95548bad44aa0f312
+ config_md5_hash=1c8dbdc086c063d95548bad44aa0f312
++ basename ./.infrastructure/conf/traefik/prod/traefik.yml
++ tr '[:lower:]' '[:upper:]'
++ tr . _
+ config_md5_var=SPIN_MD5_HASH_TRAEFIK_YML
+ eval SPIN_MD5_HASH_TRAEFIK_YML=1c8dbdc086c063d95548bad44aa0f312
++ SPIN_MD5_HASH_TRAEFIK_YML=1c8dbdc086c063d95548bad44aa0f312
+ export SPIN_MD5_HASH_TRAEFIK_YML
+ compose_args+=("--compose-file" "$compose_file")
+ local docker_host=ssh://[email protected]:22
+ echo '📤 Deploying Docker stack with compose files: docker-compose.yml docker-compose.prod.yml on XXX.XXX.XXX.XXX...'
📤 Deploying Docker stack with compose files: docker-compose.yml docker-compose.prod.yml on XXX.XXX.XXX.XXX...
+ docker -H ssh://[email protected]:22 stack deploy --compose-file docker-compose.yml --compose-file docker-compose.prod.yml --detach=false --prune spin-production
unknown flag: --detach
See 'docker stack deploy --help'.
+ cleanup_on_exit
+ local exit_code=125
+ '[' 125 -ne 0 ']'
+ echo '❌ Failure detected. Cleaning up local services...'
❌ Failure detected. Cleaning up local services...
+ stop_registry
+ docker ps -q -f name=spin-registry
+ grep -q .
+ echo 'Stopping local Docker registry...'
Stopping local Docker registry...
+ docker stop spin-registry
+ echo 'Local Docker registry stopped.'
Local Docker registry stopped.
+ cleanup_ssh_tunnel
+ '[' -n 54801 ']'
+ ps -p 54801
+ echo 'Stopping local SSH tunnel...'
Stopping local SSH tunnel...
+ kill 54801
+ echo 'Local SSH tunnel stopped.'
Local SSH tunnel stopped.
+ exit 125

Oh, I believe I’ve updated to the latest Spin CLI also when I was prompted (either when I ran spin provision or spin deploy, can’t rememeber).

Spin Version:
v3.0.2 [stable] (User Installed)

This is the command to debug. It’s saying --detach is not found. How it works is it’s using your local Docker client to connect to your server over SSH to run the deployment.

I wonder if your local Docker client is out of date.

I am running Version: 27.4.0 on macOS with latest Docker Desktop. If you post the contents of spin debug from your local machine.

If your version on your client comes back as modern, then I would go into the server and run a sudo docker info to check that version too

Hey. Sorry for the delay. And thanks again for the help. I’ve installed the same Docker version as you locally but still get an error. The server has version 27.5.0.

Error as below:

+ docker -H ssh://[email protected] stack deploy --compose-file docker-compose.yml --compose-file docker-compose.prod.yml --detach=false --prune spin-production
error during connect: Get "http://docker.example.com/v1.47/info": command [ssh -o ConnectTimeout=30 -T -l deploy -p 22 -- XXX.XXX.XXX.XXX docker system dial-stdio] has exited with exit status 255, make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: [email protected]: Permission denied (publickey).

+ cleanup_on_exit
+ local exit_code=1
+ '[' 1 -ne 0 ']'
+ echo '❌ Failure detected. Cleaning up local services...'
❌ Failure detected. Cleaning up local services...

Looks like I hadn’t added my default key to the ssh agent. Works fine now :wink:

For those that get stuck, just run ssh-add.

But the question I have now is, how would I add a certificate to the server and a custom domain? I guess that’s out of scope of spin though.