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 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘