dsfhe34889789708 2018-11-28 09:42
浏览 177

如何在Docker容器上运行Golang Web应用

I have a web app that uses go language as it's back end. When I run my website I just do go build; ./projectName then it will run on local server port 8000. How do I run this web app on a container? I can run sample images like nginx on a container, but how do I create my own images for my projects. I created a Dockerfile inside my project folder with the following codes:

FROM nginx:latest

WORKDIR static/html/

COPY . /usr/src/app

Then made an image using the Dockerfile, but when I run it on a container and go to localhost:myPort/static/html/page.html it says 404 page not found. My other question is, does docker can only run static pages on a container? cause my site can receive and send data. Thanks

this is my docker file (./todo is my project name and folder name)

this is my terminal ( as you can see the the container exits emmediately)

  • 写回答

3条回答 默认 最新

  • doutu2017 2018-11-28 11:24
    关注

    I guess you are not exposing the Docker Port outside the container. That's why you are not able to see any output rather than just being specific to GO Program. Try adding the below lines to your docker compose File

    EXPOSE 80(whichever port you want it to be)
    EXPOSE 443
    EXPOSE 3306
    

    This will make the container be accessed from outside

    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示