Error trying to deploy to AWS

I just encountered an error when trying to deploy my Wappler app to AWS EC2. This has not happened before.

Building web
[+] Building 0.3s (9/9) FINISHED
 => [internal] load build definition from Dockerfile                                                                                             0.0s 
 => => transferring dockerfile: 32B                                                                                                              0.0s 
 => [internal] load .dockerignore                                                                                                                0.0s 
 => => transferring context: 34B                                                                                                                 0.0s 
 => [internal] load metadata for docker.io/wapplerio/node-12:latest                                                                              0.0s 
 => [1/4] FROM docker.io/wapplerio/node-12                                                                                                       0.0s 
 => [internal] load build context                                                                                                                0.0s 
 => => transferring context: 34B                                                                                                                 0.0s 
Building db
Sending build context to Docker daemon  67.07kB
Step 1/2 : FROM postgres:11.1
 ---> 5a02f920193b
Step 2/2 : COPY db_init/ /docker-entrypoint-initdb.d/
 ---> Using cache
 ---> ae98ea0ed01a
Successfully built ae98ea0ed01a
Successfully tagged benchmark__staging_db:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context wil
l have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Building web
Sending build context to Docker daemon  3.593MB
Step 1/4 : FROM wapplerio/node-12
 ---> 7f4100422308
Step 2/4 : COPY ./ /opt/node_app/
 ---> b02e8ad50d36
Step 3/4 : WORKDIR /opt/node_app
 ---> Running in d016f5c177f3   
Removing intermediate container d016f5c177f3
 ---> 7d8c1e138d65
Step 4/4 : RUN npm install --no-optional --production
 ---> Running in 69c6127e994d
npm WARN deprecated node-pre-gyp@0.11.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbo
x scoped package will recieve updates in the future
npm WARN deprecated uuid@3.3.2: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known
 to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known
 to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated   
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated

> aws-sdk@2.930.0 postinstall /opt/node_app/node_modules/aws-sdk
npm WARN lifecycle benchmark@1.0.0~postinstall: cannot run in wd benchmark@1.0.0 bash ./tools/install.sh (wd=/opt/node_app)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","ar
ch":"x64"})

added 38 packages from 21 contributors, removed 11 packages, updated 72 packages and audited 888 packages in 23.185s

12 packages are looking for funding
  run `npm fund` for details

found 1 low severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details
Removing intermediate container 69c6127e994d
 ---> 4956f43b23c8
Successfully built 4956f43b23c8
Successfully tagged benchmark__staging_web:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context wil
l have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Recreating benchmark__staging_redis_1 ... 
Recreating benchmark__staging_db_1    ... 
Recreating benchmark__staging_db_1    ... done
Recreating benchmark__staging_web_1   ... 
WARNING: Host is already in use by another container
Recreating benchmark__staging_web_1   ... error

ERROR: for benchmark__staging_web_1  Cannot start service web: driver failed programming external connectivity on endpoint benchmark__staging_web_1 (1
aad45e1ab0a85a07b3615b9c34ed99f5750191859f3cd50b9439b7b95073388): Bind for 0.0.0.0:80 failed: port is already allocated

ERROR: for web  Cannot start service web: driver failed programming external connectivity on endpoint benchmark__staging_web_1 (1aad45e1ab0a85a07b3615
b9c34ed99f5750191859f3cd50b9439b7b95073388): Bind for 0.0.0.0:80 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
Error Launching Services!

Here is my docker-compose.yml (sensitive information has been removed):

version: '3'
services:
  db:
    environment:
      POSTGRES_PASSWORD:
      POSTGRES_USER:
      POSTGRES_DB:
    volumes:
      - 'db-volume:/var/lib/postgresql/data'
    ports:
      - '9906:5432'
    restart: always
    build:
      context: .
      dockerfile: db/Dockerfile
  web:
    depends_on:
      - db
    environment:
      AUTH_ENDPOINT:
      TOKEN_ENDPOINT:
      USERINFO_ENDPOINT:
      LOGOUT_ENDPOINT:
      SMART_DOMAIN:
      MEASUREMENT_ID:
      CLIENT_ID:
      CLIENT_SECRET:
      MODE: staging
    restart: always
    stdin_open: true
    tty: true
    build:
      context: ../../../
      dockerfile: .wappler/targets/Staging/web/Dockerfile
    labels:
      - traefik.enable=true
      - traefik.http.routers.myweb.tls.certresolver=myresolver
      - >-
        traefik.http.routers.myweb.rule=Host(``)
    ports:
      - '80:3000'
  redis:
    image: 'redis:alpine'
    hostname: redis
    networks:
      proxy: ~
    volumes:
      - 'redis-volume:/data'
networks:
  proxy:
    external:
      name: wappler-compose_proxy
volumes:
  db-volume: ~
  letsencrypt:
    driver: local
  redis-volume: ~

I’ve tried reverting my code to the last successful deployment and even tried to start out from a completely fresh EC2 instance but the error persists and I’m out of ideas.
Does anyone know how to resolve this issue?

Try stopping all running containers/services on the EC2 instance first. Then attempt again.

Already tried this. Even tried with a completely fresh EC2 instance, and I get the same error.

Also could try changing the port to 8080 (remember to make corresponding changes AWS side) in docker-compose.yml see if that rectifies it?

SSH in and run:

docker ps

and see what is using port 80 and run (to stop the offending Container):

docker stop CONTAINER ID

Tried port 8080 but then I just get:

ERROR: for b24d7eac65d8_benchmark__staging_web_1  Cannot start service web: driver failed programming external connectivity on endpoint benchmark__sta
ging_web_1 (fab077a6fc9bf74aa4dff5446864c82ac85301f9f833beef12c9680eee2d4ec3): Bind for 0.0.0.0:8080 failed: port is already allocated

Also, I’ve already tried deleting all containers, networks, volumes, etc. I’ve tried both a complete reset of Docker on the instance and tried a completely fresh EC2 instance. Both gave the exact same error.

What Wappler version are you on?

I am running Wappler v3.9.9.

It seems that the ports you want to use are already in use at your server. Is there something else running on it?

Make sure you set the AWS security group you are using to allow for traffic to port 8080.

I got the error even with a completely fresh EC2 instance with nothing yet running on it.

@Dave not sure about the security group settings, will try it.

It is one of the reasons you could see the error (with setting 8080 in the docker-compose.yml file and not in your AWS security group configuration for the user accessing the instance) you are witnessing @Anders

Allowing traffic through port 8080 didn’t help resolve the issue. It’s still the same:

Bind for 0.0.0.0:8080 failed: port is already allocated

Very strange you would think an entirely new Instance and all the above would resolve the issue one way or another. Could it be a local conflict with Docker Desktop? Thinking aloud… Is it worth recreating your Targets? Although I can’t see that making much of a difference… Or removing the Local Target if you have one, try clearing the old Containers out of your Local Docker environment? Again thinking out aloud here…

Really appreciate you taking your time to help me resolve this!

I asked a colleague to try to deploy from his machine and he got the same error for what it’s worth.

I’m relatively new to Docker and AWS so unfortunately don’t have a great deal of experience to go on but will continue to pick my brain and Stack Overflow for alternative answers.

Do you have multiple projects running on the same docker server?

Do you use Traefik for SSL?

No this is the only project running on the Docker server and yes, I use Traefik for SSL (installed using Wappler).

That is the problem then - there is a catch when using Trafiek - you have to leave the project web ports empty as Traefik takes care of all.

It is actually in the docs:

1 Like

Ah thank you so much! I’ll look into this during the day and report back.

Thank you taking your time with this issue, much appreciated!