- MongoDB Atlas: I use the service as it uses the same AWS infustructure, but presents an easier configuration
- AWS Beanstalk: a managed service for deploying apps, in this case a docker image
- So this means you will want to an account with Amazon Web Services(AWS)
- dockerhub: like github, but for hosting docker images. dockerhub
install docker on your machine
once that is accomplished, create an account on dockerhub
then: docker login
this will allow you to push your local images to dockerhub, which from there we will pull from AWS beanstalk.
I would create a directory which will house the configuration files that you will use for deployment.
mkdir -p ~/AwsDocker/Kalicos/.ebextensionscd ~/AwsDocker/Kalicos/touch Dockerrun.aws.jsonThis is the main config file that will tell AWS Beanstalk where the image is, what port it will expose, and where to find the log filestouch .ebextensions/.configThis file is required to export the necessary environment variables to the running docker container.
The Dockerrun.aws.json file will look something like this:
{
"AWSEBDockerrunVersion": 1,
"Image": {
"Name": "<organizationName>/kalicos.server",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "8080"
}
],
"Logging": "/usr/src/app"
}.ebextensions/.config file will look something like this
option_settings:
- option_name: NODE_ENV
value: production
- option_name: Port
value: 8080
...(the rest of your production keys you want to export to Beanstalk)From here, I recommend also creating a few shell scripts for testing and generating assets
First: touch ~/AwsDocker/Kalicos/build.sh
docker build -t kalicos.server /location/to/Kalicos/server/which you can call using: sh ~/AwsDocker/Kalicos/build.sh, or sh build.sh if you are in the directory.
This will generate the image you will eventually push to dockerhub
Second: touch ~/AwsDocker/Kalicos/zip-build.sh
zip -r kalicos-deploy.zip Dockerrun.aws.json .ebextensionsWhen you are on the Aws Beanstalk console, and ready to upload the deployment file, kalicos-deploy.zip is what you want to choose.
Third: touch ~/AwsDocker/Kalicos/run-local.sh
docker run -d -p 4000:8080 \
-e NODE_ENV=production \
-e PORT=8080 \
... \
kalicos.serverThis is how you might run the image on your local environment as if it were production, this is useful to ensure everything you will push up to dockerhub works as expected
cd ~/AwsDocker/Kalicossh build.shsh run-local.shyou can check to see the image works as expected onlocalhost:4000sh zip-build.shonly if you changed anything about your configurationdocker tag kalicos.server <organizationName>/kalicos.serverin my caseccodrington/kalicos.serverdocker push <organizationName>/kalicos.server- AWS Beanstalk console: create docker application if you haven't already, and in the deploy section, upload kalicos-deploy.zip
- if you have done this already, and none of the configuration has changed, it should update to new image when you push to dockerhub