stevejb
stevejb

Reputation: 2444

Dockerfile for Yesod deployment

I am working on a Yesod app which I would like to deploy using Docker. I am using stack for building and the app works as expected when interacting locally using stack exec -- yesod devel. I would now like to put this on a remote server, using Docker for deployment.

I realize that I can either

  1. Have the Dockerfile orchestrate the compilation and build locally
  2. Put the binary inside a Docker image, push image up to a repository, and pull to server.

Assuming going route #2, I have the following Dockerfile:

FROM haskell:7.10

MAINTAINER stevejb <stevejb>

RUN mkdir /yesodapp
COPY config /yesodapp/config
COPY static /yesodapp/static
COPY ./.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/sjb-app/sjb-app /yesodapp/sjb-app

EXPOSE 3000
ENTRYPOINT ["/yesodapp/sjb-app"]

However, this does not do anything. When I try to start the app manually from within the container, it does not do anything. I think I am missing something simple here.


In stack.yaml,

image:
    container:
        name: stevejb/sjb-app
        base: fpco/stack-run
        add:
            config: /app/config
            static: /app/static

Then,

$ stack image container
Sending build context to Docker daemon 30.08 MB
Sending build context to Docker daemon 
Step 0 : FROM fpco/stack-run
 ---> db9b2a858ef5
Step 1 : ADD ./ /
 ---> 69d4ae832c0e
Removing intermediate container 4c6dd4edc16d
Successfully built 69d4ae832c0e
$ $ docker run --rm  -p 3000:3000 stevejb/sjb-app
*** Running /etc/my_init.d/00_regen_ssh_host_keys.sh...
*** Running /etc/rc.local...
*** Booting runit daemon...
*** Runit started as PID 17
*** Running sudo -EHu root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /usr/bin/env -- bash...
*** sudo exited with status 0.
*** Shutting down runit daemon (PID 17)...
*** Killing all processes... 

Also, I noticed that this does not generate a Dockerfile. Is the yesodweb dockerfile made by hand?

Upvotes: 0

Views: 306

Answers (1)

Michael Snoyman
Michael Snoyman

Reputation: 31345

First guess would be that you need to change your working directory to /yesodapp.

Since you're already using Stack, you may be interested in trying out its Docker container generation capabilities. An example is in the yesodweb.com code base. In the stack.yaml file, we have:

resolver: lts-3.0
image:
    container:
        name: snoyberg/yesodweb
        base: fpco/stack-run
        add:
            config: /app/config
            static: /app/static

Then running stack image container generates a snoyberg/yesodweb Docker image.

You may also be interested in checking out the Kubernetes deployment scripts I use for yesodweb.com.

Upvotes: 1

Related Questions