docker-compose+nuxt cannot access localhost:3000.

Asked 1 years ago, Updated 1 years ago, 149 views

Thank you for your continuous support.
Currently, we are trying to create a docker+nuxt development environment by referring to here.
However, when I access it with localhost:3000 from the host side, I get an error as below and I can't connect...

$curl'http://localhost:3000/'
curl —(52) Empty reply from server

I looked at various websites and looked into them, but I'm troubled because I don't know the cause.
Could you tell me the cause?

docker-compose.yml

version: '3'

services:
  nuxt:
    build:./Dockerfiles/nuxt
    container_name —Shaken_tech_nuxt
    volumes:
      - ./src: /var/www/html
    working_dir: /var/www/html/client
    command: bash-c "yarn dev&/bin/bash"
    tty —true
    stdin_open —true
    environment:
      PORT—3000
      HOST: 0.0.0.0
    ports:
      - "3000:3000"

Dockerfile

 FROM node: 10.19-alpine

# install libraries
RUN apk add -- update\
    bash\
    make\
    git\
    curl\
  &rm-rf/var/cache/apk/*

RUNnpm update-gnpm

package.json

…omitted
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
  },
  …abbreviated

nuxt.config.js

export default {
  mode: 'spa',
  // server: {
  //   port —3000,
  //   host: '0.0.0.0'
  // },
  …abbreviated
}

http://localhost:3000 was successfully accessed and the nuxt initial screen was displayed

Behavior changes without setting HOST to docker-compose.yml environment.

HOST Without settings

yarn dev displays Listening on:http://localhost:3000/.
Log in to the guest side at another terminal and run curl

$curl'http://localhost:3000/'
curl:(7) Failed to connect to localhost port 3000: Connection refused

Log in to the host side at another terminal and run curl

$curl'http://localhost:3000/'
curl —(52) Empty reply from server

HOSTIf configured

yarn dev displays Listening on:http://172.18.0.3:3000/.
※ IP changes every time docker is started.
Log in to the guest side at another terminal and run curl

$curl'http://localhost:3000/'
curl:(7) Failed to connect to localhost port 3000: Connection refused

$ curl'http://172.18.0.3:3000/'
<!doctype html>
<html>
HTML is displayed
</html>

Log in to the host side at another terminal and run curl

$curl'http://localhost:3000/'
curl —(52) Empty reply from server

I have changed the description below.

"dev":"nuxt",

"dev": "NUXT_HOST=0.0.0 NUXT_PORT=3000 nuxt",

I tried both HOST and NUXT_HOST as described in the nuxt document, and curl on the host side showed the same result.

I tried as described in nuxt document, and the result was the same when curl was done on the host side.

Reproduction Environment

$docker-v
Docker version 19.03.5, build 633a0ea
$ docker-compose-v
docker-compose version 1.25.4, build 8d51620a
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.3
BuildVersion: 19D76

I have installed ESET, but I'm testing the firewall, so I don't think it's around the network.

https://web.plus-idea.net/on/docker-web-server-access-denied/
I checked one by one with reference to this one, but I don't know how to solve the problem even if I try curl'http://localhost:3000/' from the guest side.

If anyone knows the solution, could you please let me know?
Thank you for your cooperation.

docker docker-compose nuxt.js

2022-09-30 21:46

1 Answers

I referred to the same site.

It is not listed on the site, but there is a part where people ask about telemetry, and I think it would not have started without answering y/n.

https://github.com/nuxt/telemetry

as shown at the bottom of the .
telemetry:false

If you add to nuxt.config.js, you won't be asked for telemetry, so I think you'll get up even if you run yarn dev on docker-compose.


2022-09-30 21:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.