简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM