0

I tried to host docker container in my EC2, just for UAT (for production, we will fargate). My concern is I want to host my container in EC2 and run all test cases, after successfully will be deployed to fargate.

Here is appspec.yml

version: 0.0
os: linux
files:
  - source: /
    destination: /root/MY-BACKEND
    overwrite: true
hooks:
  BeforeInstall:
    - location: ./scripts/before_install.sh
      timeout: 300
      runas: root
  AfterInstall:
    - location: ./scripts/after_install.sh
      timeout: 300
      runas: root
  ApplicationStart:
    - location: ./scripts/app_start.sh
      timeout: 300
      runas: root
  ApplicationStop:
    - location: ./scripts/app_stop.sh
      timeout: 300
      runas: root
  ValidateService:
    - location: ./scripts/validate_server.sh
      timeout: 300
      runas: root

and after_install.sh

  cd /root/MY-BACKEND
  docker build -t my-backend .

and app_start.sh

  cd /root/MY-BACKEND
  docker run -d -p 80:2019 --name my-docker my-backend

and validate_server.sh

  curl -m 5 http://0.0.0.0

After that, I've encountered following error message from Validate Server [stderr]curl: (52) Empty reply from server

And when changed to curl -m 5 http://localhost, encountered following error message [stderr]curl: (56) Recv failure: Connection reset by peer

But when I open browser, my app is working either tried curl from my local and remote server, both are working. Please let me know which I missed to add some validation.

  • Often browsers do more stuff than curl when trying to access a particular URL. Open the browser's development tools (maybe in an incognito window) and re-load that url to see what it's doing (authentication, session setup, etc). Then try to adjust curl's options to do the same thing. Also the environment in which scripts are executed typically differs between automated tools and user-invoked (for example user invocations use an interactive shell session, automated tools do not). – Dan Cornilescu Jul 15 at 2:52
  • I've got solution by myself now. – PPShein Jul 15 at 3:54
  • @PPShein Would be good if you could share this solution then. – Cyclonecode Jul 22 at 10:20
  • @Cyclonecode I've answered it by myself. – PPShein Jul 22 at 10:30
0

I've found solution. Problem is backend took 10 mins to make fully loaded. When curl -m 5 http://0.0.0.0 in validate_server.sh, backend is not ready yet to response back that's why [stderr]curl: (56) Recv failure: Connection reset by peer throw. So, I've added sleep 20s above curl -m 5 http://0.0.0.0 inside validate_server.sh, now it was working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.