I'm running Lumen instance in a docker container using this command:
CMD php -s 0.0.0.0:80 -t public
Is it ok for production API's? I just noticed, it is php development server.. i wonder, is there a php production server built-in? How do you run your Lumen's inside a docker container without a web-server? (Installing webserver is not needed in my case)
You basically have two choices. Either you use php -s, or you set up a webserver. There is no "production webserver" built into lumen. That's what the apaches/nginxes of this world are for.
You could just use an apache+php image. nginx is a bit harder to set up.
i see, it's just my internal API, no need for nginx/apache. What the difference between php artisan serve and php -S - it is basically the same builtin webserver?
Do you know, what do i need to install in order to make postgres connection work in a container, i'm using php:7.3-fpm-alpine image, here's my full Dockerfile:
FROM php:7.3-fpm-alpine
RUN apk add --update \
&& docker-php-ext-install pgsql pdo_pgsql
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/bin --filename=composer
COPY . /app
RUN cd "/app" && cp .env.production .env && composer install
WORKDIR /app
EXPOSE 80
CMD php -S 0.0.0.0:80 -t public
But it doesn't connect to my pgsql instance, probably i do miss something else.
It depends on where your postgres server is. If it's somewhere outside of docker it should just work by referencing it as a hostname or ip number.
If it's also a docker container, there are 2 possibilities.
One, you want it to be part of a "grouping" where your php container and postgres container form a set together. If that's the case, use docker-compose. Then you can just use the name of your postgres container as the hostname. It does mean you need to set up a docker-compose config file. Once you get the hang of it this is a very powerful setup.
Or two, if you have a dedicated docker postgres container, you need to allow the 2 containers to see eachother. You do that by creating a docker network and configuring that network on both containers.