Nginx 服务器不是 运行 Gatsbyjs 默认 Docker 图像
Nginx server not running with Gatsbyjs default Docker image
我有一个正在运行的 gatsbyjs
项目,它 运行 来自官方 Docker 图片。
这是Dockerfile
:
FROM gatsbyjs/gatsby:latest
ADD public/ /pub
(编译后的网站位于 public/
,我已确认 index.html
正确呈现网站)
我也试了官方的Dockerfile
,没用:
FROM gatsbyjs/gatsby:onbuild
我从 docker-compose
中 运行 如下:
version: '3'
services:
website:
build: .
ports:
- "80:80"
Nginx returns“500 内部服务器错误”。
我正在学习官方教程here。
更新 latest
图像时似乎没有重建 onbuild
图像,这导致 docker 提取基础图像的过时版本。
您最好忽略 onbuild
图像并使用最新的图像。
Here你可以找到详细信息。
测试最新图像是否有效。
首先我尝试 运行 图像中的容器:
$ docker run -d -p 80:80 gatsbyjs/gatsby:latest
这行得通。 Nginx 运行宁在这里。
$ curl localhost
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
删除容器。
我将全局安装 gatsby
$ npm install --global gatsby-cli
现在我从 here.
克隆了一个基本的 gatsbyjs 站点
$ git clone https://github.com/gatsbyjs/gatsby-starter-hello-world.git
$ cd gatsby-starter-hello-world\
我将构建站点(如您的文档中所述)。
$ npm 安装
$盖茨比构建
现在我有一个 public/
存储库。这是带有 :onbuild
标签的图像所期望的。
LICENSE README.md node_modules/ package-lock.json package.json public/ src/
现在我可以在 git 存储库中编写我的 Dockerfile。我将使用最新的标签(不是 onbuild),这意味着我必须编写自己的 COPY
或 ADD
步骤。它包含:
FROM gatsbyjs/gatsby:latest
COPY public/ /pub
我将构建 docker 图像
$ docker build -t my-site .
Sending build context to Docker daemon 2.791MB
Step 1/2 : FROM gatsbyjs/gatsby:latest
---> 21fc487ad83e
Step 2/2 : COPY public/ /pub
---> 87f5ea1018ee
Removing intermediate container fd35cace6ef0
Successfully built 87f5ea1018ee
Successfully tagged my-site:latest
最后我可以从图像启动一个 docker 容器。
$ docker run -d -p 80:80 my-site
现在我可以 curl
我的 localhost:80
$ curl localhost
$<!DOCTYPE html><html><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="ie=edge"/><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/><link rel="preload" href="/component---src-pages-index-js-3a9c8c6504e39c44af75.js" as="script"/><link rel="preload" href="/path---index-a0e39f21c11f6a62c5ab.js" as="script"/><link rel="preload" href="/app-fcd7d98e3197e34ce021.js" as="script"/><link rel="preload" href="/commons-eef92a68af65d2662677.js" as="script"/><style id="gatsby-inlined-css"></style></head><body><div id="___gatsby"><div data-reactroot="" data-reactid="1" data-react-checksum="-122217258"><div data-reactid="2">Hello world!</div></div></div><script id="webpack-manifest">/*<![CDATA[*/window.webpackManifest={"231608221292675":"app-fcd7d98e3197e34ce021.js","35783957827783":"component---src-pages-index-js-3a9c8c6504e39c44af75.js","142629428675168":"path---index-a0e39f21c11f6a62c5ab.js"}/*]]>*/</script><script>/*<![CDATA[*/!function(e,t,r){function n(){for(;d[0]&&"loaded"==d[0][f];)c=d.shift(),c[o]=!i.parentNode.insertBefore(c,i)}for(var..
我有一个正在运行的 gatsbyjs
项目,它 运行 来自官方 Docker 图片。
这是Dockerfile
:
FROM gatsbyjs/gatsby:latest
ADD public/ /pub
(编译后的网站位于 public/
,我已确认 index.html
正确呈现网站)
我也试了官方的Dockerfile
,没用:
FROM gatsbyjs/gatsby:onbuild
我从 docker-compose
中 运行 如下:
version: '3'
services:
website:
build: .
ports:
- "80:80"
Nginx returns“500 内部服务器错误”。
我正在学习官方教程here。
更新 latest
图像时似乎没有重建 onbuild
图像,这导致 docker 提取基础图像的过时版本。
您最好忽略 onbuild
图像并使用最新的图像。
Here你可以找到详细信息。
测试最新图像是否有效。
首先我尝试 运行 图像中的容器:
$ docker run -d -p 80:80 gatsbyjs/gatsby:latest
这行得通。 Nginx 运行宁在这里。
$ curl localhost
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
删除容器。
我将全局安装 gatsby
$ npm install --global gatsby-cli
现在我从 here.
克隆了一个基本的 gatsbyjs 站点$ git clone https://github.com/gatsbyjs/gatsby-starter-hello-world.git
$ cd gatsby-starter-hello-world\
我将构建站点(如您的文档中所述)。 $ npm 安装 $盖茨比构建
现在我有一个 public/
存储库。这是带有 :onbuild
标签的图像所期望的。
LICENSE README.md node_modules/ package-lock.json package.json public/ src/
现在我可以在 git 存储库中编写我的 Dockerfile。我将使用最新的标签(不是 onbuild),这意味着我必须编写自己的 COPY
或 ADD
步骤。它包含:
FROM gatsbyjs/gatsby:latest
COPY public/ /pub
我将构建 docker 图像
$ docker build -t my-site .
Sending build context to Docker daemon 2.791MB
Step 1/2 : FROM gatsbyjs/gatsby:latest
---> 21fc487ad83e
Step 2/2 : COPY public/ /pub
---> 87f5ea1018ee
Removing intermediate container fd35cace6ef0
Successfully built 87f5ea1018ee
Successfully tagged my-site:latest
最后我可以从图像启动一个 docker 容器。
$ docker run -d -p 80:80 my-site
现在我可以 curl
我的 localhost:80
$ curl localhost
$<!DOCTYPE html><html><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="ie=edge"/><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/><link rel="preload" href="/component---src-pages-index-js-3a9c8c6504e39c44af75.js" as="script"/><link rel="preload" href="/path---index-a0e39f21c11f6a62c5ab.js" as="script"/><link rel="preload" href="/app-fcd7d98e3197e34ce021.js" as="script"/><link rel="preload" href="/commons-eef92a68af65d2662677.js" as="script"/><style id="gatsby-inlined-css"></style></head><body><div id="___gatsby"><div data-reactroot="" data-reactid="1" data-react-checksum="-122217258"><div data-reactid="2">Hello world!</div></div></div><script id="webpack-manifest">/*<![CDATA[*/window.webpackManifest={"231608221292675":"app-fcd7d98e3197e34ce021.js","35783957827783":"component---src-pages-index-js-3a9c8c6504e39c44af75.js","142629428675168":"path---index-a0e39f21c11f6a62c5ab.js"}/*]]>*/</script><script>/*<![CDATA[*/!function(e,t,r){function n(){for(;d[0]&&"loaded"==d[0][f];)c=d.shift(),c[o]=!i.parentNode.insertBefore(c,i)}for(var..