Estoy intentando conectarme a la base de datos con mi otro contenedor y siempre me arroja connect ECONNREFUSED 127.0.0.1:3306
.
No entiendo donde está problema de visibilidad entre contenedores.
Dockerfile
FROM node:latest
RUN useradd --user-group --create-home --shell /bin/false app
ENV HOME=/home/app
COPY package.json $HOME/my_project/
RUN chown -R app:app $HOME/*
USER app
WORKDIR $HOME/my_project
RUN npm install --silent --progress=false
USER root
COPY . $HOME/my_project
RUN chown -R app:app $HOME/*
USER app
docker-compose.yml
version: '3'
networks:
my_network:
driver: bridge
services:
database:
container_name: my_mysql
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: www_test
MYSQL_USER: root
MYSQL_PASSWORD: root
ports:
- '3306:3306'
volumes:
- '~/docker-volumes/test/mysql:/var/lib/mysql'
restart: always
networks:
- my_network
app:
container_name: my_app
build: .
command: 'npm run serve'
ports:
- '3000:3000'
depends_on:
- database
volumes:
- '.:/home/app/my_project'
- /home/app/my_project/node_modules
restart: always
networks:
- my_network
docker exec -ti app ping database
database
que es nombre del servicio que le diste al container de la base.