Self Host with Docker #3362
Unanswered
hendra-jti
asked this question in
Help
Replies: 1 comment
-
|
hydrogen apps can definitely be containerized. the issue is the preview server binds to localhost by default which doesnt work in docker. you need to bind to 0.0.0.0 to allow connections from outside the container. here is working dockerfile: FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
EXPOSE 3000
# key: bind to 0.0.0.0 not localhost
CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0"]if using vite directly: CMD ["npx", "vite", "preview", "--host", "0.0.0.0", "--port", "3000"]docker-compose example: services:
hydrogen:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=productionalso check your package.json preview script. if it uses vite, you might need to update it: "scripts": {
"preview": "vite preview --host 0.0.0.0"
}for production deployment, you probably want to use the actual hydrogen server instead of preview. check if theres a serve or start script that uses the shopify remix server. test with: docker build -t hydrogen-app .
docker run -p 3000:3000 hydrogen-appthen access http://localhost:3000 from your host machine. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am attempting to containerize my Shopify Hydrogen app with Docker. While the build process (npm run build) completes successfully, running the preview server inside a Docker container fails. it can't forward the port from the container to host.
Any explanation for me ? this project is can be containerized or not.
Thanks for the advice
Beta Was this translation helpful? Give feedback.
All reactions