Vite/Docker: localhost didn’t send any data. ERR_EMPTY_RESPONSE

I’m trying to run a vanilla js vite project in docker:

docker-compose.yml

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>version: '3'
services:
app:
build: .
ports:
- "5173:5173"
volumes:
- .:/usr/src/app
command: npm run dev
</code>
<code>version: '3' services: app: build: . ports: - "5173:5173" volumes: - .:/usr/src/app command: npm run dev </code>
version: '3'
services:
  app:
    build: .
    ports:
      - "5173:5173"
    volumes:
      - .:/usr/src/app
    command: npm run dev

Dockerfile

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># Use the official lightweight Node.js 14 image.
# https://hub.docker.com/_/node
FROM node:19
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
# Install vite globally in the Docker container.
RUN npm install
# Install all dependencies.
RUN npm install -g vite
# Copy local code to the container image.
COPY . .
</code>
<code># Use the official lightweight Node.js 14 image. # https://hub.docker.com/_/node FROM node:19 # Create and change to the app directory. WORKDIR /usr/src/app # Copy application dependency manifests to the container image. # A wildcard is used to ensure both package.json AND package-lock.json are copied. # Copying this separately prevents re-running npm install on every code change. COPY package*.json ./ # Install vite globally in the Docker container. RUN npm install # Install all dependencies. RUN npm install -g vite # Copy local code to the container image. COPY . . </code>
# Use the official lightweight Node.js 14 image.
# https://hub.docker.com/_/node
FROM node:19

# Create and change to the app directory.
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./

# Install vite globally in the Docker container.
RUN npm install

# Install all dependencies.
RUN npm install -g vite

# Copy local code to the container image.
COPY . .

docker-compose up --build

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Creating network "vite-docker_default" with the default driver
Building app
[+] Building 4.9s (11/11) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 622B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:19 0.7s
=> [internal] load build context 0.0s
=> => transferring context: 1.29kB 0.0s
=> [1/6] FROM docker.io/library/node:19@sha256:92f06fc13bcc09f1ddc51f6ebf 0.0s
=> CACHED [2/6] WORKDIR /usr/src/app 0.0s
=> CACHED [3/6] COPY package*.json ./ 0.0s
=> [4/6] RUN npm install 3.0s
=> [5/6] RUN npm install -g vite 1.0s
=> [6/6] COPY . . 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:916da68b6a643e1d85ea3625a71b5c2c49ca528b90f6d8 0.0s
=> => naming to docker.io/library/vite-docker_app 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Creating vite-docker_app_1 ... done
Attaching to vite-docker_app_1
app_1 |
app_1 | > [email protected] dev
app_1 | > vite
app_1 |
app_1 |
app_1 | VITE v5.2.10 ready in 130 ms
app_1 |
app_1 | ➜ Local: http://localhost:5173/
app_1 | ➜ Network: use --host to expose
</code>
<code>Creating network "vite-docker_default" with the default driver Building app [+] Building 4.9s (11/11) FINISHED => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 622B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/node:19 0.7s => [internal] load build context 0.0s => => transferring context: 1.29kB 0.0s => [1/6] FROM docker.io/library/node:19@sha256:92f06fc13bcc09f1ddc51f6ebf 0.0s => CACHED [2/6] WORKDIR /usr/src/app 0.0s => CACHED [3/6] COPY package*.json ./ 0.0s => [4/6] RUN npm install 3.0s => [5/6] RUN npm install -g vite 1.0s => [6/6] COPY . . 0.0s => exporting to image 0.1s => => exporting layers 0.1s => => writing image sha256:916da68b6a643e1d85ea3625a71b5c2c49ca528b90f6d8 0.0s => => naming to docker.io/library/vite-docker_app 0.0s Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them Creating vite-docker_app_1 ... done Attaching to vite-docker_app_1 app_1 | app_1 | > [email protected] dev app_1 | > vite app_1 | app_1 | app_1 | VITE v5.2.10 ready in 130 ms app_1 | app_1 | ➜ Local: http://localhost:5173/ app_1 | ➜ Network: use --host to expose </code>
Creating network "vite-docker_default" with the default driver
Building app
[+] Building 4.9s (11/11) FINISHED                                               
 => [internal] load build definition from Dockerfile                        0.0s
 => => transferring dockerfile: 622B                                        0.0s
 => [internal] load .dockerignore                                           0.0s
 => => transferring context: 2B                                             0.0s
 => [internal] load metadata for docker.io/library/node:19                  0.7s
 => [internal] load build context                                           0.0s
 => => transferring context: 1.29kB                                         0.0s
 => [1/6] FROM docker.io/library/node:19@sha256:92f06fc13bcc09f1ddc51f6ebf  0.0s
 => CACHED [2/6] WORKDIR /usr/src/app                                       0.0s
 => CACHED [3/6] COPY package*.json ./                                      0.0s
 => [4/6] RUN npm install                                                   3.0s
 => [5/6] RUN npm install -g vite                                           1.0s
 => [6/6] COPY . .                                                          0.0s 
 => exporting to image                                                      0.1s 
 => => exporting layers                                                     0.1s 
 => => writing image sha256:916da68b6a643e1d85ea3625a71b5c2c49ca528b90f6d8  0.0s 
 => => naming to docker.io/library/vite-docker_app                          0.0s 

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Creating vite-docker_app_1 ... done
Attaching to vite-docker_app_1
app_1  | 
app_1  | > [email protected] dev
app_1  | > vite
app_1  | 
app_1  | 
app_1  |   VITE v5.2.10  ready in 130 ms
app_1  | 
app_1  |   ➜  Local:   http://localhost:5173/
app_1  |   ➜  Network: use --host to expose

When I open http://localhost:5173/ in the browser I get:

enter image description here

There are no logs in the container

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật