# Deploy to Docker Swarm on AWS

**URL:** <https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952>\
**Category:** Deployments\
**Tags:** aws, docker\
**Created:** [March 9, 2017, 4:12pm UTC](https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952 "2017-03-09T16:12:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![skinofstars](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/skinofstars/32/15625_2.png) [@skinofstars](https://discuss.circleci.com/u/skinofstars)\
**Post date:** [March 9, 2017, 4:12pm UTC](https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952/1 "2017-03-09T16:12:51Z")

</div>

Hey all,

I’m wondering if anyone has managed to attach to their circle docker client to a swarm and deployed to it?

I’ve gotten as far as building and pushing my image, and I can connect locally to a swarm, but I can’t seem to do the auth in circle. If anyone has managed it, I’d love to know how.

Thanks,  
Kevin

---

<div class="post-metadata">

**Author:** ![levlaz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/levlaz/32/36978_2.png) [@levlaz](https://discuss.circleci.com/u/levlaz)\
**Post date:** [March 10, 2017, 2:05am UTC](https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952/2 "2017-03-10T02:05:45Z")

</div>

@FelicianoTech any pointers here?

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [March 14, 2017, 7:46pm UTC](https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952/3 "2017-03-14T19:46:25Z")

</div>

I don’t have experience with Docker Swarm, sorry. ☹

---

<div class="post-metadata">

**Author:** ![zzak](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/zzak/32/4233_2.png) [@zzak](https://discuss.circleci.com/u/zzak)\
**Post date:** [March 15, 2017, 8:01am UTC](https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952/4 "2017-03-15T08:01:12Z")

</div>

Hello @skinofstars,

Thank you for your question!

After a google search I was able to find this blog post:

> **[Continuous deployment w/ Docker, AWS and circle-ci – soosap – Medium](https://medium.com/soosap/continuous-deployment-w-docker-aws-and-circle-ci-82f4b14256cc#.fsmfiorl9)**
>
> So there you go, you have worked your ass off to build that awesome web application on your local development machine, but when it…

Hopefully that helps you, please don’t forget to share your solution back here!

Best, Zak

---

<div class="post-metadata">

**Author:** ![skinofstars](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/skinofstars/32/15625_2.png) [@skinofstars](https://discuss.circleci.com/u/skinofstars)\
**Post date:** [March 20, 2017, 3:19pm UTC](https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952/5 "2017-03-20T15:19:42Z")

</div>

Thanks for the article. However, that’s really more around how one pushes/pulls from docker hub, rather than connecting to a swarm.

I think my problem is more around how I attach to the swarm. I’ve started a thread over at the docker forums.

> **[Deploying in swarm mode - CI/CD](https://forums.docker.com/t/deploying-in-swarm-mode-ci-cd/30008)**
>
> Hi, I'm trying to work out how best to automate deployment with the new Swarm mode. As far as I can see, there are a few options, but in each case I've mostly hit a blocker of some kind. 1. Via the dockercloud/client This approach seems like...

---

<div class="post-metadata">

**Author:** ![jpatters](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jpatters/32/14938_2.png) [@jpatters](https://discuss.circleci.com/u/jpatters)\
**Post date:** [May 10, 2017, 2:41am UTC](https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952/6 "2017-05-10T02:41:36Z")

</div>

I’ve got this working but it feels so hacky.  
I read your post on the docker forum as well and I agree that option number one is ideal so that’s what I worked towards as well.

```
docker run --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -e DOCKER_HOST dockercloud/client help

```

That shows a lot of information; namely that you can use `-u` and `-p` to specify the username and password. So:

```
docker run --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -e DOCKER_HOST dockercloud/client -u $DOCKER_USER -p $DOCKER_PASS $SWARM

```

Will remove the need for it to be interactive.  
The next problem was that by running the `export` command that is output, you no longer have access to a docker host. The docs state:

> For security reasons, the Docker Executor doesn’t allow building Docker images within a job space.

So the issue is that the container that is started by the dockercloud client isn’t on the job host. It’s on a remote host already. So changing `DOCKER_HOST` on in the job space removes access to the remote host.  
Instead, what I did was start another container in the remote host to run the swarm commands, like so:

```
docker run --rm -e DOCKER_HOST=172.17.0.1:32768 -v /var/run/docker.sock:/var/run/docker.sock docker:17.03.1-ce docker service list

```

Note the IP address is not the IP that is output by the dockercloud client command. It is the internal (inside the docker bridge network) IP that is assigned to the dockercloud client-proxy container. Also note that I specified the version of docker to match the version running in the swarm.

This all feels really hacky to me and it would be nice is someone from CircleCI could comment on if there is a more straight forward way to accomplish this. Or if there are more improvements coming in 2.0 that would make this easier.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![stephenlautier](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/stephenlautier/32/16102_2.png) [@stephenlautier](https://discuss.circleci.com/u/stephenlautier)\
**Post date:** [May 16, 2017, 7:35pm UTC](https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952/7 "2017-05-16T19:35:29Z")

</div>

I’m also working on a same exact scenario and I’m having the same exact issue due to the remote docker host of circleci.

Any help in order to make this more straight forward/simple/automated is highly appreciated

---

<div class="post-metadata">

**Author:** ![shaned24](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/shaned24/32/9833_2.png) [@shaned24](https://discuss.circleci.com/u/shaned24)\
**Post date:** [August 10, 2017, 11:11pm UTC](https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952/8 "2017-08-10T23:11:57Z")

</div>

`docker inspect -f \'{{(index (index .NetworkSettings.Ports "2375/tcp") 0).HostPort}}\' client_proxy_swarm_name`

I just grabbed the host forwarded port of the running proxy client then applied it to the environment

My use case was in jenkins but i’m sure you can do the same in circle ci

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:41am UTC](https://discuss.circleci.com/t/deploy-to-docker-swarm-on-aws/10952/9 "2018-06-18T11:41:13Z")

</div>


