Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use stack image container?

Stack can build a docker container to run your app on a server with the stack image container command (See references below).

How do I connect to the web server in the docker container created this way?

I've build a simple app to demonstrate the issue. See the complete code here: https://github.com/seanhess/haskell-docker-example

This app was built from stack new with minimal changes. Here's Main.hs

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Network.Wai
import Network.HTTP.Types (status200)
import qualified Network.Wai.Handler.Warp as Warp

main :: IO ()
main = Warp.run 8010 app

app :: Application
app req respond = do
    (putStrLn $ "Request: " ++ (show req))
    (respond $ responseLBS status200 [] "Hello World")

And stack.yaml

resolver: nightly-2016-06-12

image:
  container:
    name: haskell-docker-example
    base: fpco/stack-run

This app responds with "Hello world" if you run it locally.

stack build
stack exec haskell-docker-example

But if you build the docker image and start it:

stack image container
docker run -it -p 8010:8010 haskell-docker-example

Requests reach the docker container, but we get an empty response error because there's nothing behind it.

$ curl -i http://localhost:8010
curl: (52) Empty reply from server

References:

  • http://www.yesodweb.com/blog/2015/12/yesod-hosting-docker-kubernetes
  • https://github.com/commercialhaskell/stack/issues/2337
  • http://docs.haskellstack.org/en/stable/GUIDE/#docker

Update: I'm poking around more. When I attach to the running container, my app is definitely not running. If I attempt to execute it by hand I get the following error:

/usr/local/bin/haskell-docker-example-exe
bash: /usr/local/bin/haskell-docker-example-exe: cannot execute binary file: Exec format error

Some googling suggests this can come when trying to execute 64 bit code on a 32 bit system. Is that possible? If it matters I'm on mac osx.

like image 778
Sean Clark Hess Avatar asked Jul 06 '16 15:07

Sean Clark Hess


People also ask

How do I use image stack in Flutter?

image_stack is a pure dart package for creating image stack in Flutter. This package give you a widget to easily create image stack for your need. UI created by this package is mainly found in profile picture stacks in so many apps but it can be used at any place where you feel it will look good.


1 Answers

The executable I was building locally (OSX) was not runnable on the docker container. The solution was to build with docker. I changed stack.yaml to the following:

# we have to switch to an LTS resolver, because the stack-build
# docker image doesn't support nightly. 
resolver: lts-6.6

docker:
  enable: true

image:
  container:
    name: haskell-docker-example
    base: fpco/stack-run

Then I rebuilt, now using the docker image

stack build
stack image container

And it runs great! Looks like you need to manually specify that you want to run the executable though:

docker run -it -p 8010:8010 haskell-docker-example /usr/local/bin/haskell-docker-example-exe

Alternatively, run stack with --docker, which will override the docker setting in stack.yml (also you don't need to run stack build separately):

stack --docker image container
like image 120
Sean Clark Hess Avatar answered Sep 23 '22 17:09

Sean Clark Hess