Hello, i am getting a connection refused error between 2 containers running through…
- User
Hello, i am getting a connection refused error between 2 containers running through docker compose. My containers are on the same network, I am still getting an error message from the react container when connecting to the backend: cause: Error: connect ECONNREFUSED 172.19.0.6:443 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) { errno: -111, code: ‘ECONNREFUSED’, syscall: ‘connect’, address: ‘172.19.0.6’, port: 443 } }
My docker compose file looks like this: version: "3.2" services: backend: container_name: php build: context: . dockerfile: Dockerfile extra_hosts: - "host.docker.internal:host-gateway" depends_on: - mysql - mongodb command: | bash -c " composer migrate -- --up && php-fpm" taskmanager: container_name: taskmanager build: context: . dockerfile: Dockerfile extra_hosts: - "host.docker.internal:host-gateway" depends_on: - mysql command: | bash -c "php-fpm" apache: container_name: apache build: './config/docker/apache/' depends_on: - php - mysql memcached: container_name: memcached image: memcached:alpine restart: always mysql: container_name: mysql build: './config/docker/mysql/' restart: always environment: MYSQL_ROOT_PASSWORD: somepassword ports: - "3306:3306" nginx: container_name: nginx build: './config/docker/nginx/' depends_on: - apache ports: - "80:80" - "443:443" mongodb: container_name: mongodb image: mongo restart: always environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: somepassword ports: - "27017:27017" frontend: container_name: react build: './react/' ports: - "4230:4230" command: | bash -c " pnpm install && pnpm dev frontend"
However when i am trying to access backend from frontend it doesn't work. I am using insecure connection and react (frontend) is set up to ignore SSL certificates with process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
- Assistant
There are a few things that could be causing the connection refused error between your containers in Docker Compose:
-
Make sure that your backend container is listening on the correct port (443 in this case). You can check this by running
docker psand looking at the "PORTS" column for your backend container. -
Check that your backend container is actually up and running. You can run
docker psand look for the "STATUS" column to see if it's healthy. -
Ensure that your React frontend container has access to the backend container's IP address. You can do this by adding a
linkssection to yourdocker-compose.ymlfile:
yamlservices: frontend: ... links: - backend backend: ...This will create a DNS entry for the
backendcontainer in the container's file. -