Error: connect ECONNREFUSED 127.0.0.1:8000 Error: connect ECONNREFUSED 127.0.0.1:8000 docker docker

Error: connect ECONNREFUSED 127.0.0.1:8000


Looks like your port mapping is wrong. In your docker compose you're mapping nginx port 8081 to port 80 of your computer. Maybe you need to map 8081:8000, provided that your nginx config actually starts a service at port 8081 and makes the appropiate proxy redirections to the nuxt host (nuxt:3000).

Or maybe your vuejs code needs to update port to http://localhost/ since you're mapping to port 80 in your compose file.


Inside of a container, localhost or 127.0.0.1 maps to the container, not to the external host, unless you turn off the network namespace (not recommended). We don't see the app listening on 8000 in your question, so the general advice looks like:

Between containers, you need to place both containers on the same user created docker network, connect to the container or service name as the hostname, and connect to the application port, not a published port on the host. Compose sets up the networks for you by default, e.g. from "nuxt" you could curl http://nginx:80/.

To talk from the container to an app on the host, not running on a container, either move that app into a container and follow the steps above, or connect to the host DNS or IP rather than localhost.


From your edit, the above applies. You can either keep the two projects separate and change the hostname/IP to that of your host. Or you can connect the two projects over a shared network, e.g.:

docker network create backend

And then add the shared network to each compose file:

version: "3"services:  nuxt:    build: ./app/    container_name: nuxt    restart: always    ports:      - "3000:3000"    networks:      - default      - backend    command:      "npm run start"  nginx:    image: nginx:1.13    container_name: nginx    ports:      - "8081:80"    volumes:      - ./nginx:/etc/nginx/conf.d    depends_on:      - nuxtnetworks:  backend:    external: true

And for the other project:

version: "3"services:  mariadb:    image: wodby/mariadb:$MARIADB_TAG    container_name: "${PROJECT_NAME}_mariadb"    stop_grace_period: 30s    environment:      MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD      MYSQL_DATABASE: $DB_NAME      MYSQL_USER: $DB_USER      MYSQL_PASSWORD: $DB_PASSWORD  php:    image: wodby/drupal-php:$PHP_TAG    container_name: "${PROJECT_NAME}_php"    environment:      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025      DB_HOST: $DB_HOST      DB_USER: $DB_USER      DB_PASSWORD: $DB_PASSWORD      DB_NAME: $DB_NAME      DB_DRIVER: $DB_DRIVER      PHP_FPM_USER: wodby      PHP_FPM_GROUP: wodby      COLUMNS: 80    volumes:      - ./:/var/www/htmlnginx:    image: wodby/nginx:$NGINX_TAG    container_name: "${PROJECT_NAME}_nginx"    depends_on:      - php    environment:      NGINX_STATIC_OPEN_FILE_CACHE: "off"      NGINX_ERROR_LOG_LEVEL: debug      NGINX_BACKEND_HOST: php      NGINX_SERVER_ROOT: /var/www/html/web      NGINX_VHOST_PRESET: $NGINX_VHOST_PRESET    volumes:      - ./:/var/www/html    labels:      - 'traefik.backend=${PROJECT_NAME}_nginx'      - 'traefik.port=80'      - 'traefik.frontend.rule=Host:${PROJECT_BASE_URL}'  mailhog:    image: mailhog/mailhog    container_name: "${PROJECT_NAME}_mailhog"    labels:      - 'traefik.backend=${PROJECT_NAME}_mailhog'      - 'traefik.port=8025'      - 'traefik.frontend.rule=Host:mailhog.${PROJECT_BASE_URL}'  portainer:    image: portainer/portainer    container_name: "${PROJECT_NAME}_portainer"    command: --no-auth -H unix:///var/run/docker.sock    volumes:      - /var/run/docker.sock:/var/run/docker.sock    labels:      - 'traefik.backend=${PROJECT_NAME}_portainer'      - 'traefik.port=9000'      - 'traefik.frontend.rule=Host:portainer.${PROJECT_BASE_URL}'  traefik:    image: traefik    container_name: "${PROJECT_NAME}_traefik"    command: -c /dev/null --web --docker --logLevel=INFO    ports:      - '8000:80'    networks:    - default    - backend    volumes:      - /var/run/docker.sock:/var/run/docker.socknetworks:  backend:    external: true

And then change your connection from localhost:8000 to traefik:80.