Vito Corleone
Vito Corleone

Reputation: 141

How to expose vite js host to the outside docker

I'm new in vite js when upgrade from Laravel version 8 to 9. I'm building docker for a Laravel 9 project use vite js. There is a problem: I can't expose host of resources out of docker containers. It's still working in the inside docker containers. Are there any advice ? Thanks.

This is my docker-compose file

version: "3.9"

services:
  nginx:
    image: nginx:1.23-alpine
    ports:
      - 80:80
    mem_limit: "512M"
    volumes:
      - type: bind
        source: ./api
        target: /usr/share/nginx/html/api
      - type: bind
        source: ./docker/nginx/dev/default.conf
        target: /etc/nginx/conf.d/default.conf

  php:
    platform: linux/amd64
    build:
      context: .
      dockerfile: ./docker/php/dev/Dockerfile
    mem_limit: "512M"
    volumes:
      - type: bind
        source: ./api
        target: /usr/share/nginx/html/api

  oracle:
    platform: linux/amd64
    image: container-registry.oracle.com/database/express:21.3.0-xe
    ports:
      - 1521:1521
      # - 5500:5500
    volumes:
      - type: volume
        source: oracle
        target: /opt/oracle/oradata

volumes:
  oracle:

Upvotes: 4

Views: 5025

Answers (2)

Vito Corleone
Vito Corleone

Reputation: 141

I figured out issue. Caused vite does not expose host to network. My solution is:

  1. edit file package.json
"scripts": {
  "dev": "vite --host",
  "build": "vite build"
}
  1. expose 5173 port in docker-compose.yml file
php:
    platform: linux/amd64
    build:
      context: .
      dockerfile: ./docker/php/dev/Dockerfile
    mem_limit: "512M"
    ports:
      - 5173:5173
    volumes:
      - type: bind
        source: ./api
        target: /usr/share/nginx/html/api

Upvotes: 9

katxeus
katxeus

Reputation: 9

There has been voiced downsides to named volumes @David Maze.

Since you can't access the contents of a named volume from outside of Docker, they're harder to back up and manage, and a poor match for tasks like injecting config files and reviewing logs.

Would you try altering all volume types to bind.

Mount volume from host in Dockerfile long format

Upvotes: -1

Related Questions