Search code examples
curldockeramazon-ec2docker-swarm

Can not curl docker swarm from remote host


I'm trying to test how to interact with docker swarm using docker API. I have an ec2 instance in AWS running docker. I need to connect to it from my local machine using curl then initialize the swarm and get the join tokens after to use it to connect 2 other ec2 instances to the swarm. I need to do all of that using curl only.

I created the swarm manually by ssh'ing to the instance and running:

docker swarm init --advertise-addr 10.0.0.2

and then I tried running this curl command:

curl 10.0.0.2:2377/swarm
curl 10.0.0.2:2377/info

and I get an empty line. If I try changing the port to 2376 I get connection refused error.

What am I missing?

running netstat -tuplen, found the following result:

enter image description here


Solution

  • To pull the answer out of the comments: By default accessing the remote API has to be done with https authentication. You can turn that off but this isn't recommended for production apps. There may be a way to write an authorization plugin that will allow other forms of authentication access.