0

I am trying to dockerise my elm application (code is open source), here is my Dockerfile:

# set base image as alpine
FROM alpine:3.11.2 AS builder

# download the elm compiler and extract it to /user/local/bin/elm
RUN wget -O - 'https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz' \
    | gunzip -c >/usr/local/bin/elm

# make the elm compiler executable
RUN chmod +x /usr/local/bin/elm

# update remote repositories
RUN apk update

# install nodejs
RUN apk add --update nodejs npm

# install uglifyjs
RUN npm install uglify-js --global

# set the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD
# instructions that follows the WORKDIR instruction.
WORKDIR /app

# remember, our current working directory within the container is /app
# we now copy everything (except stuff listed in .dockerignore)
# from local machine to /app (in the container).
COPY . .

# build elm production code
RUN elm make src/app/Main.elm --optimize --output=elm.js

When I run docker build . --no-cache I get the following error:

ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [AI_ADDRCONFIG], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = , addrCanonName = }, host name: Just "package.elm-lang.org", service name: Just "443"): does not exist (Try again)

Here is what it looks like:

elm make error inside docker container

I don't have any connection issues, plus if I did have any, then you'd think the install of nodejs and uglifyjs would also fail, correct? Yet those install without any problems.

I'm confused and not really sure what I need to do.

J86
  • 14,345
  • 47
  • 130
  • 228
  • 1
    There are a lot of possible connection issues between no internet and being unable to reach a specific server. A good place to start is to `ping` `package.elm-lang.org`. – glennsl Dec 27 '19 at 21:13
  • thanks @glennsl, you're right. I went ahead and added `RUN ping package.elm-lang.org` instruction to my `Dockerfile` and I got this: https://i.imgur.com/zBooDpS.png – J86 Dec 27 '19 at 21:16
  • 1
    Does it consistently fail at `elm/html`? Looks like the previous elm packages are getting resolved just fine – prithajnath Dec 27 '19 at 21:25
  • Good question @prithajnath, no it sometimes fails on `elm/browser` too. – J86 Dec 27 '19 at 21:26
  • I have [a project](https://github.com/Lattyware/massivedecks/blob/master/client/Dockerfile#L5) building elm code with `node:13-alpine` image and don't see this (other differences include use the Elm NPM package and webpack rather than `elm make` directly). As you are installing node anyway, that image might be a better starting point. – Gareth Latty Dec 30 '19 at 23:29
  • Thanks @GarethLatty how does one build for production with the Elm npm package? Would the command be the same? – J86 Dec 31 '19 at 12:25
  • 1
    @J86 Yeah, if you install it globally with NPM, it should just be on your path. Or you can just use `npx` to run the `elm` install in `node_modules` once you have the NPM package installed locally (i.e: `npx elm make src/app/Main.elm --optimize --output=elm.js` if we were to modify your example to use a local elm pacakge). – Gareth Latty Jan 01 '20 at 13:32
  • @GarethLatty it failed again, and again, it was on the same step (i.e. when it tries to download elm packages). It was very strange, so I decided to try it on Windows, and to my surprise, it worked fine on Windows!! But on Linux, it fails. I'm very confused, I thought docker worked best with Linux. My Linux distro is Manjaro. – J86 Jan 02 '20 at 00:50

1 Answers1

0

Looks like this is an OS level networking problem. An easy hack would be to wrap the make command in an infinite retry loop (in a different script) and run that script instead

#!/usr/bin/env bash

while :
do
  elm make src/app/Main.elm --optimize --output=elm.js
  [ $? -eq 0 ] &&  exit # exit if above command is successful
done

And in your Dockerfile, change the last line to

# build elm production code
RUN ./retry.sh
prithajnath
  • 2,000
  • 14
  • 17
  • What about going for the next best thing? After `alpine` what is the next lightest distribution of linux? Perhaps I can try the docker image of that? – J86 Dec 27 '19 at 21:58
  • Alpine is the most commonly used Docker image that is lightweight afaik. You can try your luck with Debian or Ubuntu but they're not as lightweight – prithajnath Dec 27 '19 at 22:04