Deploying Meteor With Docker on AWS ECS
I originally gave a talk on this subject for April’s Meteor Dev Shop NYC. The slides are available here: mazlix.github.io/meteor-docker-deploys/.
If you already have Docker installed move along. Otherwise: https://docs.docker.com/mac/ has install instructions for Mac and links for Linux and Windows. I haven’t found installing docker to be 100% painless, namely that after installing they give you a “Docker Quickstart Terminal”, but if you’re like me and like running your own terminal like iTerm you’ll need to often use this handy command: `eval $(docker-machine env default — shell bash)`
While that previous step is building, we can spend this time looking for a database. Assuming your app uses MongoDB, we’re going to want to have a separate database instance that our app can connect to. I use mlab.com for lots of things because it’s good and free. But compose.io is another great solution if you’re looking for something that has Oplog support right out the box. In any case you’re going to need a database.
Once you’ve got your mongodb:// URL with a username/pass we’re ready to move on.
Assuming you have your meteor app finished and you’re ready to push it out the world here’s how you can do it in a nice scalable way.
Use https://github.com/meteorhacks/meteord: (The docs here are great so feel free to just go off that README if you run into any issues on these steps.)
- Put a Dockerfile (plain text file with the name “Dockerfile”) in the root of your app with just the text “FROM meteorhacks/meteord:onbuild”.
- Then run `docker build -t yourname/app .` (don’t ignore the “ .” at the end). This step might take a while as you’re building the entire image of a container that is capable of running meteor (with your app).
- Once that’s all done you can test it your app by running:
docker run -d \
-e ROOT_URL=http://yourapp.com \
-e MONGO_URL=mongodb://url \
-e MONGO_OPLOG_URL=mongodb://oplog_url \
-p 8080:80 \
If you’re new to Docker, after running this (assuming it didn’t throw an error) you should be able to find your Docker containers IP address by running`docker-machine ls` you can then go to your docker machine’s ip address:8080 to view your webpage.
If everything is working good and well on there then you’re good to move on the the next step!… setting up AWS.
You’re going to want to click on EC2 Container Service.
The documentation and UI menus on AWS always seem a bit confusing.
If for some reason clicking on that EC2 Container Service link doesn’t give you the wizard with instructions try going to this url: https://console.aws.amazon.com/ecs/home#/firstRun
Basically the main things you want to do are:
1) Create a docker repository on amazons’ ECS section. (this could but does not have to match your same yourname/app).
2) Once you do that it will give you instructions on how to build, tag, and push your docker image.
You’ll want to run these commands: with that second docker login command being the output of the first command.
$> aws ecr get-login — region us-east-1
$> docker login -u AWS -p ……
$> eval $(docker-machine env default — shell bash)
$> docker tag justink/test13:latest …amazonaws.com/justink/dockertest:latest
$> docker push 06…amazonaws.com/name/app:latest
Now that you’ve pushed your repository onto AWS, you’ll want to set up your actual servers and instances that will run your meteor app.
Do this by creating a task definition and putting the amazon image in the Image section.
You’ll want to make sure that your port mappings are mapping 80 to 80.
Also you’ll need to go into advanced options and set up env variables including your ROOT_URL, MONGO_URL, and any other things that you ran in the docker run step (possible METEOR_SETTINGS param).
Here’s a video followed by some screenshots of me setting this up:
I know this probably isn’t the most clear set of instructions but I really hope it’s enough to help someone get a working set up! I’ll try to edit this to make instructions more clear and would love any feedback from anyone trying this out themselves as to how I could make clearer directions. I’m also happy to try to help anyone with questions via email to firstname.lastname@example.org.
Up next will be an article on how to scale up and update your application once you get this single instance set up!