{"id":22683301,"url":"https://github.com/mtchavez/atlas-docker-compose","last_synced_at":"2025-03-29T14:40:19.824Z","repository":{"id":27592229,"uuid":"31075393","full_name":"mtchavez/atlas-docker-compose","owner":"mtchavez","description":"Use Atlas to set up a docker host to use docker-compose with","archived":false,"fork":false,"pushed_at":"2015-02-20T17:14:00.000Z","size":108,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-04T15:32:54.561Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtchavez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-20T17:13:50.000Z","updated_at":"2020-05-19T17:31:14.000Z","dependencies_parsed_at":"2022-09-07T00:52:52.071Z","dependency_job_id":null,"html_url":"https://github.com/mtchavez/atlas-docker-compose","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtchavez%2Fatlas-docker-compose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtchavez%2Fatlas-docker-compose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtchavez%2Fatlas-docker-compose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtchavez%2Fatlas-docker-compose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtchavez","download_url":"https://codeload.github.com/mtchavez/atlas-docker-compose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246200300,"owners_count":20739563,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-09T21:11:34.708Z","updated_at":"2025-03-29T14:40:19.803Z","avatar_url":"https://github.com/mtchavez.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Atlas Docker Compose\n\nThis is an example setup using [Atlas](https://atlas.hashicorp.com) to configure\na [Docker](https://docker.com) host on [AWS](https://aws.amazon.com) so that\n[Docker Compose](https://github.com/docker/fig) can be used to manage an application\non a remote host.\n\n## Purpose\n\nDocker compose, formerly fig, is great for local development and setting up\nan application. I wanted to find a way to set up a remote environment to use\ndocker compose with that could be ephemeral and easily duplicated, this is\nwhere Atlas came in to manage that setup.\n\nMy desire was to see how convenient this could be for throw away development\nservers to have hosted on a cloud provider that is interacted with the same\nway you would use Docker compose or fig locally.\n\n## Requirements\n\nYou will need a few things set up to get everything running:\n\n* AWS account\n  * There are other providers that this could be translated to in the future\n* Atlas account and your Atlas token\n* [Packer](https://packer.io) for packaging the server into an AMI\n* [Terraform](https://terraform.io) to manage the infrastructure needed\n* [Docker Compose](https://github.com/docker/fig/releases/tag/1.1.0-rc2) to manage the app docker images and containers\n  * A non fig version was used for this so `\u003e= v1.1.0`, but it may still work with older versions of fig\n\n## Setup\n\nWe are going to start out with setting everything up in Atlas. If you are not familiar\nwith Atlas please check out the [getting started](https://atlas.hashicorp.com/help/getting-started/getting-started-overview) guide.\n\nIf you are using this code you will need to replace my atlas user name everywhere\nto be your atlas username ie. `s/mtchavez/joe-user/`\n\n### Build Configuration\n\nAtlas uses [Packer](https://packer.io) to manage what they call build configurations. Look into Packer\nto see what all it can do for you. In our case we will be building and provisioning an EC2 AMI\nthat will run Ubuntu 14.04 with Docker set up.\n\nYou will need to have your environment set up with your AWS credentials. To push our build configuration\nto Atlas and have it build our AMI we run the following:\n\n```\ncd ops\n# Use -create when creating\npacker push -create ubuntu-docker.json\n\n# Otherwise just push new changes\npacker push ubuntu-docker.json\n```\n\nIf you go to your Atlas build configurations you can watch the progress and verify\nthat it has successfully built your AMI. Now that we have a provisioned Docker host\nwe need to use it by defining what our application infrasture is using Terraform.\n\n## Infrastructure State\n\nTo manager our infrasture we will be using [Terraform](https://terraform.io) and\nwill be pushing our state to Atlas. The required infrasture here is pretty simple:\n\n* A security group for our instance networking rules\n* Define an instance to launch\n* Our built AMI to use to launch our instance\n\nTo get our AMI we use Atlas to get our resource data which will have the AMI ID.\n\n```\n# Get build configuration\nresource \"atlas_artifact\" \"ubuntu-docker\" {\n    name = \"mtchavez/ubuntu-docker\"\n    type = \"aws.ami\"\n}\n```\n\nThen we reference it when defining our instance\n\n```\nresource \"aws_instance\" \"docker-host\" {\n    ami = \"${atlas_artifact.ubuntu-docker.metadata_full.region-us-west-2}\"\n    instance_type = \"t2.micro\"\n    ...\n}\n```\n\nFrom the `ops` directory you can verify your infrastructure state with `terraform plan`\nto get a detailed output of what terraform will do when it runs. When you are ready to create\nyour infrastructure simple run `terraform apply`. This will build our instance\nand you should see the public IP as output. We will need this to set up our\n`DOCKER_HOST` for using Docker compose.\n\nIf you want to save your infrastructure state to Atlas you can run `terraform push`\n\n## Docker Compose\n\nOnce your server is up and running you can now use Docker compose to push the sample\napp to our remote instance. Make sure you have Docker compose\n\n```\n$ docker-compose --version\ndocker-compose 1.1.0-rc2\n```\n\nYou will need to set up some Docker environment variables to set our new host\nand to turn of TLS. You can do this manually or source a shell script with:\n\n```\ncd app\n# Change 10.0.0.1 to the public IP of your instance\nsource bin/init_docker_shell 10.0.0.1\n```\n\nYou should verify that the following variables are set correctly:\n\n```\nDOCKER_HOST=tcp://10.0.0.1:2376\nDOCKER_TLS_VERIFY=\n```\n\nIf you are not familiar with Docker compose or fig you can read up on that [here](http://www.fig.sh/).\nNow we can use `docker-compose` to execute docker commands and manage our simple\nFlask app that has a redis dependency and linked container.\n\nTo bring up our app remotely you can simply do `docker-compose up -d`. We can verify\nour app is up and running correctly by listing out our processes:\n\n```\n$ docker-compose ps\n   Name                  Command               State           Ports\n-----------------------------------------------------------------------------\napp_redis_1   /entrypoint.sh redis-serve ...   Up      0.0.0.0:6379-\u003e6379/tcp\napp_web_1     python app.py                    Up      0.0.0.0:5000-\u003e5000/tcp\n```\n\nThis shows us that we have redis and our app up and running with our app exposed\non port 5000. If we visit our `http://$HOST:5000` the app should be running\nand incrementing page views using redis.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtchavez%2Fatlas-docker-compose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtchavez%2Fatlas-docker-compose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtchavez%2Fatlas-docker-compose/lists"}