I am trying to connect to the database with my other container and it always throws me connect ECONNREFUSED 127.0.0.1:3306
.
I don't understand where the visibility problem between containers is.
docker file
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
I have already found the solution, not indicating the driver and exposing the ports of both services.
commands