ubuntu - 如何从 Docker 提供 Harp/nginx 页面?

标签 ubuntu nginx docker harp

我正在尝试在 Docker 容器中运行 nginx 和 Harp 来为我的博客提供服务。

我发现了这个:https://github.com/octohost/harp-nginx

当我运行 sudo docker pull octohost/harp-nginx ,它会下载一堆文件,但这是我卡住的地方。
sudo docker run -d -P octohost/harp-nginx似乎什么也没做。在我运行这个之后,如果我查看 sudo docker -ps -a我可以看到容器被创建,然后在 1-2 秒后退出。我也不知道如何查看我的网站将在哪些端口上提供服务。

我知道 Docker 有几种方法可以访问父操作系统上的文件:https://blog.docker.com/2015/04/tips-for-deploying-nginx-official-image-with-docker/

我想要 harp-nginx挂载目录的容器,例如 ~/my_blog/ ,并让 Harp 即时编译这些并使用 nginx 提供它们(在自定义端口上,因为 80 已经在使用中)。我想编辑 ~/my_blog/ 中的 Markdown 源从父操作系统,并让更改自动在网站上生效。但是我不知道如何处理上面链接的 octohost 容器。我怎样才能完成我想要的?

最佳答案

When I run sudo docker pull octohost/harp-nginx, it downloads a bunch of files, but this is where I am stuck.



这些文件应该是 docker 镜像,用于创建 docker 容器。

sudo docker run -d -P octohost/harp-nginx doesn't seem to do anything. After I run this, if I look at sudo docker -ps -a I can see that the container gets created, then exits 1-2 seconds later. I also don't know how to see what ports my website will be served on.



通常,你可以查看一个容器的日志,看看是什么问题,你可以运行 docker logs <container_id/container_name>
然后我们回到你的问题,似乎 octohost/harp-nginx不执行任何命令,所以你应该自己写Dockerfile使用环境。来自 octohost/harp-nginx的 repo README ,你可以写一个Dockerfile像这样:
FROM octohost/harp-nginx

WORKDIR /srv/www

ADD . /srv/www/
RUN harp compile

EXPOSE 80

CMD nginx

然后你可以使用 docker build -t my-harp-nginx . 构建你自己的 harp-nginx 容器。 ,构建成功后,您可以使用docker run --name "harp-nginx" -d -p 8080:80 my-harp-nginx创建一个新容器

请注意,这里我们将主机的 8080 端口映射到容器的 80 端口,因此您可以从 http://localhost:8080 访问容器的端口

I want the harp-nginx container to mount a directory, for instance ~/my_blog/, and have Harp compile these on the fly and serve them with nginx (on a custom port because 80 is already in use). I want to edit the markdown source in ~/my_blog/ from the parent OS, and have the changes automatically take effect in the website. However I can't figure out what to do with the octohost container linked above. How can I accomplish what I want?



我不熟悉harp ,所以这是我的理解和建议。
  • 你应该运行 harp compile在主机而非容器中,只需将编译后的静态内容挂载到 nginx 容器中,让 nginx 为其提供服务。如果你这样做,只需使用任何 nginx docker 镜像,例如 dockerfile/nginx ,然后安装您的 harp输出到 /var/www/html .
  • 似乎 harp还不支持实时重新加载,因此您需要一些额外的工具来实现它。 [我不确定这部分,只是google了]
  • 关于ubuntu - 如何从 Docker 提供 Harp/nginx 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31365968/

    相关文章:

    ubuntu - 如何在ubuntu14.04上安装clang

    Nginx CSP frame-src 被忽略

    docker - xvfb-run 卡在容器中

    docker - Kubernetes 中的 self 修复——我们可以完全重新生成 pod 吗?

    ubuntu - 在 Ubuntu 上构建 mosync

    .net - .NET 核心 web api Ubuntu 服务器的主管设置

    linux - linux命令中的方括号后跟感叹号是什么意思?

    postgresql - ^ 和 $ 在 nginx.conf 位置做什么?

    WordPress nginx 无法创建目录 - 权限正确

    docker - 如何在 Mesos 或 CoreOS 中配置 MariaDB 和 Redis 的高可用集群