vendredi 15 décembre 2017

Ember app visible when running in host, but not in container

I'm attempting to containerize an Ember app for local development. I have ports 4200, 3529 (live reload), and 8443 (api) exposed in my Dockerfile.

I'm basing my image on Node 6.9.4 (specified in the project). When I run the app outside Docker, I can see the app when I navigate to it in my browser. When it's running inside Docker, it just hangs and the page loading spinner spins forever. I put in some logging, and it looks like the server is not seeing the request at all.

Dockerfile

FROM node:6.9.4

# open up the ports we need for the app to run
EXPOSE 4200 35729 4080 8443 9999

WORKDIR /usr/src/app

ENV PATH=/usr/src/app/bin:$PATH

ADD . /usr/src/app

RUN set -ex \
  && npm install -g ember-cli \
  && npm install -g grunt-cli \
  && npm install -g bower \
  && npm install -g protractor \
  && npm install -g check-dependencies

# set up Phantom
RUN \
  mkdir /tmp/phantomjs &&\
  curl -L http://ift.tt/1Rirpaz | tar -xvj -C /tmp/phantomjs --strip-components=1 phantomjs-2.1.1-linux-x86_64/bin &&\
  mv /tmp/phantomjs/bin/phantomjs /usr/bin &&\
  rm -rf /tmp/phantomjs

# set up Watchman
RUN set -ex \
  && export WATCHMAN_VERSION=3.0.0 \
  && curl -SL "http://ift.tt/2zuikIX" | tar -xz -C /tmp/ \
  && cd /tmp/watchman-${WATCHMAN_VERSION} \
  && ./autogen.sh \
  && ./configure \
  && apt-get update && apt-get install -y --no-install-recommends python-dev \
  && make \
  && make install \
  && apt-get purge -y --auto-remove python-dev \
  && rm -rf /var/lib/apt/lists/* \
  && rm -rf /tmp/*

docker-compose.yml

version: "2"

services:
  web:
    image: pnr
    build:
      context: .
      dockerfile: Dockerfile
    command: ember server --ssl=true
    entrypoint: /usr/src/app/development-entrypoint.sh

    volumes:
      # Mount the app code inside the container's `/usr/src/app` directory:
      - .:/usr/src/app

    # Keep the stdin open, so we can attach to our app container's process
    # and do things such as debugging, etc:
    stdin_open: true

    # Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
    tty: true

    ports:
      # Bind the host's 4200 port to the container's ember app server
      # port 4200:
      - 4200:4200
      # Bind the host's 35729 port to the container's ember cli live reload
      # server port 35729:
      - 35729:35729

      # api
      - 8443:8443

development-entrypoint.sh

#! /bin/bash

# The Docker App Container's development entrypoint.
# This is a script used by the project's Docker development environment to
# install the app dependencies automatically upon runnning.
set -e

: ${APP_PATH:="/usr/src/app"}
: ${APP_TEMP_PATH:="$APP_PATH/tmp"}
: ${APP_SETUP_LOCK:="$APP_TEMP_PATH/setup.lock"}
: ${APP_SETUP_WAIT:="5"}

# 1: Define the functions lock and unlock our app containers setup
# processes:
function lock_setup { mkdir -p $APP_TEMP_PATH && touch $APP_SETUP_LOCK; }
function unlock_setup { rm -rf $APP_SETUP_LOCK; }
function wait_setup { echo "Waiting for app setup to finish..."; sleep $APP_SETUP_WAIT; }

# 2: Specify a default command, in case it wasn't issued:
if [ -z "$1" ]; then set -- ember server --ssl=true "$@"; fi

# 3: Run the setup routine if the command is 'ember':
if [[ "$1" = "ember" ]]
then

  # 3.1: 'Unlock' the setup process if the script exits prematurely:
  trap unlock_setup HUP INT QUIT KILL TERM EXIT

  # 3.2: Wait until the setup 'lock' file no longer exists:
  while [ -f $APP_SETUP_LOCK ]; do wait_setup; done

  # 3.3: 'Lock' the setup process, to prevent a race condition with
  # another container trying to install dependencies:
  lock_setup

  # 3.4: Check or install npm/bower dependencies:
  check-dependencies

  # 3.5: 'Unlock' the setup process:
  unlock_setup
fi

# 4: Execute the given or default command:
exec "$@"

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire