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
posta un mese fa176 visualizzazioni
1 Risposta
2
Risposta accettata
profile picture
ESPERTO
con risposta un mese fa
profile picture
ESPERTO
verificato un mese fa
profile picture
ESPERTO
verificato un mese fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande