user6216601
user6216601

Reputation:

Symfony app in Docker doesn't work

I created an app in Symfony with MongoDB and I added that in a Docker image.

Image for MongoDB works good with message: 2017-04-19T12:47:33.936+0000 I NETWORK [initandlisten] waiting for connections on port 27017

But image for app dosen't work I receive the message:

stdin: is not a tty
hello

when I call the instruction: docker run docker_web_server:latest

I use for that docker-compose file:

web_server:
    build: web_server/
    ports:
        - 5000:5000
    links:
        - mongo
    tty: true
    environment:
        SYMFONY__MONGO_ADDRESS: mongo
        SYMFONY__MONGO_PORT: 27017

mongo:
   image: mongo:3.0
   container_name: mongo
   command: mongod --smallfiles
   expose:  
       - 27017

And Dockerfile for app is:

FROM ubuntu:14.04

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && apt-get install -y \
    git \
    curl \
    php5-cli \
    php5-json \
    php5-intl

RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer

ADD entrypoint.sh /entrypoint.sh
ADD ./code /var/www

WORKDIR /var/www

#RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/bin/bash", "/entrypoint.sh" ]

entrypoint.sh

#!/bin/bash
rm -rf /var/www/app/cache/*
exec php -S 0.0.0.0:8000 # This will run a web-server on port 8000

What is the problem?

I call wrong the server from docker image?

I expected to have the message:

 [OK] Server running on http://127.0.0.1:8000

Upvotes: 1

Views: 213

Answers (1)

Rawkode
Rawkode

Reputation: 22592

You should remove CMD ['echo', 'hello'] from your Dockerfile, has this is being passed as a parameter to your ENTRYPOINT

You should also add tty: true to your service definition, web-server

I'm hoping entrypoint.sh runs php -S 0.0.0.0:8000 at end. Please post that for further advice. If you do use php -S inside of it, prefix it with exec to get it to take over as the main process.

Edit since new information added:

I'd modify the entrypoint.sh to:

#!/bin/bash
rm -rf /var/www/app/cache/*
php -S 0.0.0.0:8000 # This will run a web-server on port 8000

I'd get rid of the symfony_environment.sh and instead, add the following to your web-server service:

environment:
  SYMFONY__MONGO_ADDRESS: mongo
  SYMFONY__MONGO_PORT: 27017

As a side-note, I contribute to a project called boilr that generates boilerplates, like this. I've even created a template for php/docker-compose projects, it would be worth checking out. I always keep it up-to-date with the best practices.

https://github.com/rawkode/boilr-docker-compose-php

Upvotes: 2

Related Questions