title: running a vite dev server inside a docker container
body: <p>I have a Vue-cli app that I'm trying to convert to vite. I am using Docker to run the server. I looked at a couple tutorials and got vite to run in development mode without errors. However, the browser can't access the port. That is, when I'm on my macbook's command line (outside of Docker) I can't <code>curl</code> it:</p>
  <pre><code>$ curl localhost:8080
  curl: (52) Empty reply from server
  </code></pre>
  <p>If I try localhost:8081 I get <code>Failed to connect</code>. In addition, if I run the webpack dev server it works normally so I know that my container's port is exposed.</p>
  <p>Also, if I run curl in the same virtual machine that is running the vite server it works, so I know that vite is working.</p>
  <p>Here are the details:</p>
  <p>In package.json:</p>
  <pre><code>...
  &quot;dev&quot;: &quot;vue-cli-service serve&quot;,
  &quot;vite&quot;: &quot;vite&quot;,
  ...
  </code></pre>
  <p>The entire vite.config.ts file:</p>
  <pre><code>import { defineConfig } from 'vite'
  import vue from '@vitejs/plugin-vue'
  
  // https://vitejs.dev/config/
  export default defineConfig({
      resolve: { alias: { '@': '/src' } },
      plugins: [vue()],
      server: {
          port: 8080
      }
  })
  </code></pre>
  <p>The command that starts the container:</p>
  <pre><code>docker-compose run --publish 8080:8080 --rm app bash
  </code></pre>
  <p>The docker-compose.yml file:</p>
  <pre><code>version: '3.7'
  
  services:
    app:
      image: myapp
      build: .
      container_name: myapp
      ports:
        - &quot;8080:8080&quot;
  </code></pre>
  <p>The Dockerfile:</p>
  <pre><code>FROM node:16.10.0
  
  RUN npm install -g npm@8.1.3
  RUN npm install -g @vue/cli@4.5.15
  
  RUN mkdir /srv/app &amp;&amp; chown node:node /srv/app
  
  USER node
  
  WORKDIR /srv/app
  </code></pre>
  <p>The command that I run inside the docker container for vite:</p>
  <pre><code>npm run vite
  </code></pre>
  <p>The command that I run inside the docker container for vue-cli:</p>
  <pre><code>npm run dev
  </code></pre>
  <p>So, to summarize: my setup works when running the vue-cli dev server but doesn't work when using the vite dev server.</p>