Reputation: 149
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"]
Upvotes: 0
Views: 1532
Reputation: 6534
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.
Upvotes: 1