dongzai3917 2017-11-28 04:38
浏览 499
已采纳

为什么Docker容器中的应用无法重启?

I've deployed some docker containers with golang apps. One of them I need to start by this command:

docker run --restart unless-stopped -it myapp /bin/bash

The next step I enter the container and edit some config files, then I run

go build main.go

and ./main After that I press ctrl+q and leave it out. Everything works perfectly and all my containers restart perfectly after restarting server. But there is one issue, when myapp container restarts, the golang application doesn't run while container still works. I have to enter this again and run ./main. How can I fixed it?

Dockerfile

FROM golang:1.8 
WORKDIR /go/src/app 
COPY . . 
RUN go-wrapper download # "go get -d -v ./..." 
RUN go-wrapper install # "go install -v ./..." RUN ["apt-get","update"] 
RUN ["apt-get","install","-y","vim"] 
EXPOSE 3000 
CMD ["app"]
  • 写回答

1条回答 默认 最新

  • dongruolin5324 2017-11-28 18:05
    关注

    When you create a container and pass in /bin/bash as the command, that's as far as Docker cares. When the container restarts, it will start up another instance of /bin/bash.

    Docker doesn't watch your shell session and see what things you do after it starts the command. If you want to actually run ./main as the command of the container, then you'll need to pass in /go/src/app/main as the command instead of /bin/bash.

    Additionally, compiling code is something better done during the image build phase instead of at container runtime.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀
  • ¥15 mifare plus卡认证
  • ¥30 LSTM预测结果是一条直线
  • ¥15 stnodeeditor自定义控件
  • ¥15 SDO如何更改STM32的波特率
  • ¥15 uniapp的uni-datetime-picker组件在ios端不适配
  • ¥15 前端 uniapp App端在离线状态如何使用modbus 连接手机蓝牙进行读写操控机器?