pedroremedios
pedroremedios

Reputation: 801

Unable to access port Astro app at default port 4321 in Docker container

I have setup the basic Astro skeleton app (with sample data), ran the script "npm run dev" locally and was able to access the site through localhost:4321.

When I tried to create a container from that and ran it, I was unable to access the site at localhost:4321. Below is the Dockerfile I'm using:

FROM node:18-alpine
WORKDIR /app

COPY package.json package-lock.json ./

COPY . .

RUN npm install

EXPOSE 4321

CMD [ "npm", "run", "dev" ]

and the commands I ran to build and run the container (respectively):

docker build -t personal-site-astro .
docker run -p 4321:4321 personal-site-astro

Upvotes: 2

Views: 1398

Answers (2)

Artur Czyżewski
Artur Czyżewski

Reputation: 833

If you want to listen astro dev on any IP (you need this while running inside docker container) you should add: server: { host: true},

into astro.config.mjs. This will make astro dev server listen on 0.0.0.0.

Upvotes: 3

pedroremedios
pedroremedios

Reputation: 801

Sorry I forgot I had this question still up. I managed to get it working by using the map 4322:4321. For some reason, Docker on my system doesn't like port 4321.

Upvotes: 0

Related Questions