ixx
ixx

Reputation: 32269

Run Stack Docker container

I'm confused about Stack's Docker integration.

I managed to create an image, by adding docker section to stack.yml with enable: true, as described in the integration guide.

I'm also able to start the project locally, by using

stack --docker-run-args='--net=bridge --publish=8081:8081' exec myproject

I navigate to localhost:8081 - works, great.

But how do I start the project using only Docker? With this I start the container:

docker run -d --restart=always --net=bridge --publish=8081:8081 myproject

But at this point nothing seems to be running. If I navigate to localhost:8081 I get connection refused.

Upvotes: 0

Views: 92

Answers (1)

ixx
ixx

Reputation: 32269

Problem solved!

It was missing to start the project in the container, as described in another part of Stack's docs. Specifically:

  • Either start manually the executable, which is in /usr/local/bin/ in the container (not very convenient)

  • Or configure Stack to start the executable automatically by adding the following to stack.yaml:

    image:
      containers:
        -
          name: "myimage"
          base: "baseimage"
          entrypoints:
            - myexecutable
    

After this, run stack image container to build the image (it may also be necessary to run stack build before of this).

Then ensure the image was created / check name:

docker image ls

Finally, to run it:

docker run --net=bridge --publish=8081:8081 myimage

Upvotes: 1

Related Questions