Dockerize nodejs app and deploy to EC2

Hi all,
i am very new to all of this CD/CI and i need your help.
I have a Nodejs app that i would like to automatize with CircleCI.
I would like to:

  1. Test the nodejs application.
  2. Create a Docker container
  3. Upload the container to Dockerhub
  4. Log into AWS EC2 – here i need the most help
  5. Pull the container
  6. Stop the old one
  7. Run the new one

how can i achieve this without the ECR and other amazon services, nor using teraformer.
I would like a clean login ( or ssh ) to EC2 and run a shel or some commands

thank you for your help.

Mostly, you don’t log in to CI servers - they tend to start on a Git push or a schedule.

Yes, you can do everything you want here - do one step at a time, it will seem less overwhelming. Get a bare-bones .circleci/config.yml running first, then add to it, small blobs of config at a time.

There are a variety of techniques in my config here, but this uses a standard Docker registry. AWS unfortunately does things in a non-standard way with their own binary, so you may want to do things the easy way first, then convert when it is working.

I would recommend Dockerising your app first, and running it locally. That is worth practising with for a bit - if you are new to Docker I would recommend doing some learning with it rather than moving to production immediately.

For production I would suggest standard Docker to start with, and if you are keen to have zero downtime during upgrades, look at Docker Swarm. Both are much simpler than alternatives like Kubernetes.

Good luck giving it a go, and of course do ask questions if you get stuck on something specific.

thank you.
i’ve manage to:
download docker
run tests
create docker image
push to dockerhub
ssh into EC2

but how can i run commands after logging in EC2?
do i have to add another run embeded into the earlier run?

ok, so i mange to also run commands successfully on aws EC2.

i suggest a bit more documentation on this side, i know is not cicleci but is shell scripting, but this will help allot new comers.

after ssh in i need to tel the shell that there is a small peace of code that will need to run on the remote host:

ssh -t ec2-user@ec2-xxx-xxx-xx-xxx.eu-central-1.compute.amazonaws.com <<-'ENDSSH'
      ls
      pwd
      docker ps
      docker images
      docker pull $DOCKER_USER/$IMAGE_NAME
ENDSSH
1 Like

Hi Ion. Thanks for sharing what worked. Our docs are open source, so if you think this would be good on a page you can either open a pull request or an issue (there are links to both at the bottom of every page) and we can take a look.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.