Sean Clark Hess
Sean Clark Hess

Reputation: 16079

How to use Haskell Stack with Docker Compose?

I am trying to use docker compose to tie together some haskell services for local development. Most of the time I'm messing around in stack ghci, running unit tests, etc, but I also need to be able to run code that hits a dependency. Docker compose is great for this: I can run the dependencies (databases, other services, etc), and link everything together.

Stack has docker support. It can build in a docker container with docker: enable: true, and also can create an executable image with stack image container.

How do I leverage stack's docker functionality from within docker-compose.yml?

version: "3"

services:

  my-service:

    # how can I use `stack image container` here? Is it possible?
    build: '.'

    links:
    - other-service

    env_file:
    - test.env

  other-service:
    image: other-service-image

Do I have to make my own Dockerfile, or is there some way to use the stack image container functionality?

Follow-up questions: Is there some way to run stack ghci with all the settings (env, links, etc) from the docker compose file?

Upvotes: 3

Views: 873

Answers (1)

Chris Stryczynski
Chris Stryczynski

Reputation: 34011

This only answers your follow up question (stack ghci within docker). Yes it's possible.

Depending what your service/container is named as (you can determine this with docker ps):

If your container is already running (via docker-compose up / docker run):

docker exec -it directoryName_my-service_1 /bin/stack ghci

Upvotes: 1

Related Questions