How do i Connect my Docker container in EC2 to Mysql DB in the same EC2

0

Hello pls i need help in connecting my nodejs app container in EC2 to Mysql DB(on the machine- EC2) in the same EC2 and also would really appreciate if i could be shown too how to also connect to my xampp mysql on my local computer when doing development

I am using docker-compose below is a sample code

version: "3"
services:
  backend:
    build: #Allowed[image/build]
      context: .
      dockerfile: backend/src/express/userapp/codebase/Dockerfile
      # container_name: my-custom-container-name # Specify your custom container name
      # image: my-custom-image:latest # Specify your custom image name and tag
      args:
        SOURCE_DIR: "./backend/src/express/userapp/codebase"
    ports: #[HOST_PORT:CONTAINER_PORT]
      - "4000:4000"
      # - "4000:80" # Map container port 80 (default) to host port 4000
    environment: #[Setting up my Env variable]
      - NODE_ENV=development
    volumes: #[codebase folder is where my package.json resides]
      - ./backend/src/express/userapp/codebase:/app # [Host volume (-Host:Container) for storing the Source for Live Reloading]
      - /app/node_modules #[Anonymous Volume(-Container) for my node_modules || due to bcrypt]
    # network_mode: "host" # Allow you to attach the container to a specific Docker network or host network.
    extra_hosts: #[hostname:ip_address] #using CMD[--add-host host.docker.internal:host-gateway]
      - "host.docker.internal:host-gateway"
    networks:
      - backendNet

networks:
  backendNet: {}
Nafiu
已提問 1 個月前檢視次數 178 次
1 個回答
2
已接受的答案
profile picture
專家
已回答 1 個月前
profile picture
專家
已審閱 1 個月前
profile picture
專家
已審閱 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南