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
preguntada hace un mes176 visualizaciones
1 Respuesta
2
Respuesta aceptada
profile picture
EXPERTO
respondido hace un mes
profile picture
EXPERTO
revisado hace un mes
profile picture
EXPERTO
revisado hace un mes

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas