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 优质github账号直接兑换rmb,感兴趣伙伴可以私信
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)