ssh: connect to host port 22: Connection refused

Posted May 10, 2021 722 views

When I run “docker-compose up” on my HOST machine(mac os) i’m getting this error:

ssh: connect to host port 22: Connection refused

My context is set correctly:
export DOCKER_HOST=ssh://ai-dev@

Other commands, like “docker ps -a” or “docker run” works correctly with no errors..

ssh connection to the server works..

1 comment
  • Did you find a solution? I have the exact same issue:

    • SSH into droplet => works
    • command docker --context remote ps => works
    • comman docker-compose --verbose --context remote ps=> port 22: connection refused

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Hi there,

Are you able to SSH to the server?

It sounds like that you might either have a firewall enabled on the host blocking the access to port 22, if this is the case you need to open port 22 or allow it for your IP address.

Another possible problem could be if the SSH service is not running on the host, you can check that with the following command once you login to the server via the web console:

systemctl status sshd

Also, another thing that I could suggest is to cross-check if the IP is correct.

Let me know how it goes.

  • Hey Bobby - I’m having this same problem. My SSH is working otherwise and systemctl status sshd also shows that my SSH is working correctly. I can run normal docker run docker ps commands with SSH.

    The issue only occurs with SSH. When I run docker-compose --context remote up, I receive the following output in the terminal:

    Creating network "nginx-gohttp_default" with the default driver
    ssh: connect to host <ip address of droplet> port 22: Connection refused

I had an identical issue and was able to resolve it with the following instead. Not sure why this works over the other to be honest.

docker --context=remote compose up -d