Simple HTML App with NGNIX Docker container doesn't run on Railway.app – Application failed to respond (error-503)

huangapple go评论68阅读模式
英文:

Simple HTML App with NGNIX Docker container doesn't run on Railway.app - Application failed to respond (error-503)

问题

我有一个简单的HTML应用程序。在本地一切都正常工作。以下是我的Dockerfile,它位于同一文件夹中,并且也被Railway找到。

来自Railway.app的响应:

<h1 class="error-404">Nothing here... yet</h1>
<h1 class="error-503">Application failed to respond</h1>

我的Dockerfile:

# Dockerfile
# 使用来自Docker Hub的官方nginx基础镜像
FROM nginx

# 将当前目录的内容复制到容器中的指定目录
COPY . /usr/share/nginx/html

我也尝试了这个版本(同样的结果):

# 使用来自Docker Hub的官方nginx基础镜像
FROM nginx

# 将当前目录的内容复制到容器中的指定目录
COPY . /usr/share/nginx/html

# 暴露端口80
EXPOSE 80

# 当容器提供时启动Nginx。
CMD ["nginx", "-g", "daemon off;"]

这是我的项目:

ls
app.html  assets  Dockerfile  favicon.ico  index.html  README.md

来自Railway的构建日志:

=========================
Using Detected Dockerfile
=========================
context: 13a5a...d67dbac
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 234B done
#1 DONE 0.2s
#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.2s
#3 [internal] load metadata for docker.io/library/nginx:latest
#3 DONE 0.8s
#4 [1/2] FROM docker.io/library/nginx@sha256:af296b...092305
#4 DONE 0.0s
#5 [internal] load build context
#5 transferring context: 3.58MB 0.0s done
#5 DONE 0.2s
#4 [1/2] FROM docker.io/library/nginx@sha256:af296b1...092305
#4 CACHED
#6 [2/2] COPY . /usr/share/nginx/html
#6 DONE 0.1s
#7 exporting to image
#7 exporting layers 0.0s done
#7 writing image sha256:e7fd80a...edb6b done
#7 naming to us-west1-docker.pkg.dev/railway-infra/railway-docker-users/project/8691...eefe3/service/17ba0e...d8f73:7865...df2682 0.0s done
#7 DONE 0.1s
Build time: 1.54 seconds
================
Publishing Image
================
The push refers to repository [us-west1-docker.pkg.dev/railway-infra/railway-docker-users/project/8691...efe3/service/17ba...8f73]
Preparing  f0b9a7bbdced
Preparing  4fd834341303
Preparing  5e099cf3f3c8
Preparing  7daac92f43be
Preparing  e60266289ce4
Preparing  4b8862fe7056
Preparing  8cbe4b54fa88
Waiting  4b8862fe7056
Waiting  8cbe4b54fa88
Layer already exists  4fd834341303
Pushing [>                                                  ]  53.39kB/3.58MB f0b9a7bbdced
Layer already exists  e60266289ce4
Layer already exists  5e099cf3f3c8
Layer already exists  7daac92f43be
Layer already exists  4b8862fe7056
Layer already exists  8cbe4b54fa88
Pushing [=========================>                         ]  1.837MB/3.58MB f0b9a7bbdced
Pushing [==================================================>]  3.611MB f0b9a7bbdced
Pushed  f0b9a7bbdced
7865993f...bdf2682: digest: sha256:683c0...fe44 size: 1782
Publish time: 0.64 seconds
Deploy log:
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/05/27 17:18:00 [notice] 1#1: using the "epoll" event method
2023/05/27 17:18:00 [notice] 1#1: nginx/1.25.0
2023/05/27 17:18:00 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2023/05/27 17:18:00 [notice] 1#1: OS: Linux 4.19.0-22-cloud-amd64
2023/05/27 17:18:00 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/05/27 17:18:00 [notice] 1#1: start worker processes
我不明白问题是什么。我已经重新启动、重新构建,甚至完全删除了Railway.app中的项目,然后从GitHub重新上传,然后自动生成了一个新的域名。Dockerfile需要额外的命令还是Railway.app需要在项目中设置一些内容?
<details>
<summary>英文:</summary>
I have a simple HTML application. Everything works fine locally. Here is my Dockerfile, which is in the same folder and is also found by Railway.
Response from Railway.app:
&lt;h1 class=&quot;error-404&quot;&gt;Nothing here... yet&lt;/h1&gt;
&lt;h1 class=&quot;error-503&quot;&gt;Application failed to respond&lt;/h1&gt;
[![enter image description here][1]][1]
My Dockerfile:
# Dockerfile
# Use the official nginx base image from Docker Hub
FROM nginx
# Copy the contents of the current directory to the specified directory in the container
COPY . /usr/share/nginx/html
I also tried with this version (-&gt; same results):
# Use the official nginx base image from Docker Hub
FROM nginx
# Copy the contents of the current directory to the specified directory in the container
COPY . /usr/share/nginx/html
# Expose port 80
EXPOSE 80
# Start Nginx when the container has provisioned. 
CMD [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]
This is my project:
ls
app.html  assets  Dockerfile  favicon.ico  index.html  README.md
Build logs from Railway:
=========================
Using Detected Dockerfile
=========================
context: 13a5a...d67dbac
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 234B done
#1 DONE 0.2s
#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.2s
#3 [internal] load metadata for docker.io/library/nginx:latest
#3 DONE 0.8s
#4 [1/2] FROM docker.io/library/nginx@sha256:af296b...092305
#4 DONE 0.0s
#5 [internal] load build context
#5 transferring context: 3.58MB 0.0s done
#5 DONE 0.2s
#4 [1/2] FROM docker.io/library/nginx@sha256:af296b1...092305
#4 CACHED
#6 [2/2] COPY . /usr/share/nginx/html
#6 DONE 0.1s
#7 exporting to image
#7 exporting layers 0.0s done
#7 writing image sha256:e7fd80a...edb6b done
#7 naming to us-west1-docker.pkg.dev/railway-infra/railway-docker-users/project/8691...eefe3/service/17ba0e...d8f73:7865...df2682 0.0s done
#7 DONE 0.1s
Build time: 1.54 seconds
================
Publishing Image
================
The push refers to repository [us-west1-docker.pkg.dev/railway-infra/railway-docker-users/project/8691...efe3/service/17ba...8f73]
Preparing  f0b9a7bbdced
Preparing  4fd834341303
Preparing  5e099cf3f3c8
Preparing  7daac92f43be
Preparing  e60266289ce4
Preparing  4b8862fe7056
Preparing  8cbe4b54fa88
Waiting  4b8862fe7056
Waiting  8cbe4b54fa88
Layer already exists  4fd834341303
Pushing [&gt;                                                  ]  53.39kB/3.58MB f0b9a7bbdced
Layer already exists  e60266289ce4
Layer already exists  5e099cf3f3c8
Layer already exists  7daac92f43be
Layer already exists  4b8862fe7056
Layer already exists  8cbe4b54fa88
Pushing [=========================&gt;                         ]  1.837MB/3.58MB f0b9a7bbdced
Pushing [==================================================&gt;]  3.611MB f0b9a7bbdced
Pushed  f0b9a7bbdced
7865993f...bdf2682: digest: sha256:683c0...fe44 size: 1782
Publish time: 0.64 seconds
Deploy log:
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/05/27 17:18:00 [notice] 1#1: using the &quot;epoll&quot; event method
2023/05/27 17:18:00 [notice] 1#1: nginx/1.25.0
2023/05/27 17:18:00 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2023/05/27 17:18:00 [notice] 1#1: OS: Linux 4.19.0-22-cloud-amd64
2023/05/27 17:18:00 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/05/27 17:18:00 [notice] 1#1: start worker processes
I don&#39;t understand what the problem is. I have already restarted, rebuilt and even completely deleted the project from Railway.app and uploaded it again from GitHub and then auto-generated a new domain.
Does Dockerfile need additional commands or does Railway.app need to set something in the project?
[1]: https://i.stack.imgur.com/2Gi1j.png
</details>
# 答案1
**得分**: 2
感谢Balint的评论,我终于找到了解决方案。我错误地认为端口80默认处于活动状态。您必须创建一个名为"PORT"的项目变量,其值为"80"。显然,Railway会在项目中查找此变量,如果没有此变量,端口将不会被公开。
<details>
<summary>英文:</summary>
Thanks to the comment from Balint, I finally found the solution. I wrongly assumed that port 80 is active by default. You have to create a project variable &quot;PORT&quot; with the value &quot;80&quot;. Apparently Railway searches for this variable in the project and without this variable the port is not exposed.
</details>

huangapple
  • 本文由 发表于 2023年5月28日 01:15:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76348107.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定