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: {}
1개 답변
2
수락된 답변
profile picture
전문가
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전
profile picture
전문가
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠