How do I serve a Harp/nginx page from Docker?

I’m trying to run nginx and Harp in a Docker container to serve my blog.

I’ve found this: https://github.com/octohost/harp-nginx

  • VisualVM connection to Tomcat hosted on Docker
  • Boot2Docker on Mac - Returns bsdthread_register error
  • Docker+Rails+Postgres: app can't access database container
  • '--link' does not seem to work to connect two Docker containers
  • pyftpdlib Networkprotocol Error
  • Generic cluster of docker containers on marathon
  • When I run sudo docker pull octohost/harp-nginx, it downloads a bunch of files, but this is where I am stuck.

    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.

    I know that there are several ways for Docker to access files on the parent OS: https://blog.docker.com/2015/04/tips-for-deploying-nginx-official-image-with-docker/

    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?

  • Setting-up containers reverse proxy
  • How can I detect if there's a new docker image without using docker pull?
  • Install/Start YARN in Docker
  • Securing a Docker container with HTTP BASIC AUTH
  • How to download Docker images without a direct internet connection
  • Docker-Compose file has yaml.scanner.ScannerError
  • One Solution collect form web for “How do I serve a Harp/nginx page from Docker?”

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

    These bunch of files should be the docker images, which to be used to create docker container.

    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.

    Usually, you can check the logs of a container to see what is the problem, you can run docker logs <container_id/container_name>

    Then we back to your problem, seems octohost/harp-nginx doesn’t execute any command, so you should write your own Dockerfile to use the environment. From octohost/harp-nginx‘s repo README, you can write a Dockerfile like this:

    FROM octohost/harp-nginx
    
    WORKDIR /srv/www
    
    ADD . /srv/www/
    RUN harp compile
    
    EXPOSE 80
    
    CMD nginx
    

    then you can build your own harp-nginx container by using docker build -t my-harp-nginx ., after build success, you can create a new container by using docker run --name "harp-nginx" -d -p 8080:80 my-harp-nginx

    Note that here we map host 8080 port to container’s 80 port, so you can access your container’s port from 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?

    I am not familiar with harp, so here is my understand and suggestions.

    • You should run harp compile in the host but not container, just mount the compiled static content to nginx container and let nginx to serve it. If you do this, just use any nginx docker image such as dockerfile/nginx, then mount your harp output to /var/www/html.

    • Seems harp doesn’t support live reload yet, so you need some extra tools to make it happen. [I am not sure about this part, just googled]

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.