2

I'm quite newbie with using Docker and I'm trying to create a local development environment for running either my custom php or laravel projects.

This is my folder structure

root-dir
- src // this is where my php / laravel code lives
-- info.php // file having phpinfo(); just to ensure that everything has set properly
- docker // this is where all containers and config settings live
-- php etc..
- docker-compose.yml

This is my docker/php/Dockerfile

FROM ubuntu:18.04

ENV TERM=linux

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y curl zip unzip --no-install-recommends apt-utils ca-certificates
RUN apt-get install -y --no-install-recommends php7.2-fpm \
                       php7.2-cli \
                       php7.2-mysql \
                       php7.2-xml \
                       php7.2-curl \
                       php7.2-bcmath \
                       php7.2-bz2 \
                       php7.2-curl \
                       php7.2-zip \
                       php7.2-gd \
                       php7.2-gettext \
                       php7.2-zip \
                       php7.2-soap \
                       php7.2-odbc \
                       php7.2-json \
                       php7.2-geoip \
                       php7.2-igbinary \
                       php7.2-imagick \
                       php7.2-mbstring \
                       php7.2-msgpack \
                       php7.2-ssh2 \
                       php7.2-memcached \
                       php7.2-xdebug \
                       php7.2-intl \
                       php7.2-opcache \
                       php7.2-readline

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* ~/.composer


COPY php.ini /etc/php/$PHPVER/cli/php.ini
COPY php.ini /etc/php/$PHPVER/fpm/php.ini
COPY 20-xdebug.ini /etc/php/$PHPVER/cli/conf.d/20-xdebug.ini
COPY 20-xdebug.ini /etc/php/$PHPVER/fpm/conf.d/20-xdebug.ini
COPY php-fpm-startup /usr/bin/php
CMD /usr/bin/php

EXPOSE 9000

ENTRYPOINT ["/usr/bin/php"]
CMD ["--version"]

When I'm running docker-compose up -d I get this error

ERROR: for php  Cannot start service php: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/usr/bin/php\": permission denied": unknown

This is my nginx/default.conf file

server {

  listen 80 default_server;
  root /var/www/html;
  index index.html index.php;

  charset utf-8;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location = /favicon.ico { access_log off; log_not_found off; }
  location = /robots.txt { access_log off; log_not_found off; }

  access_log off;
  error_log /var/log/nginx/error.log error;

  sendfile off;

  client_max_body_size 100m;

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
  }

  location ~ /\.ht {
    deny all;
  }
}
1
  • So you have some files and an error. But where is the question? Do you want to know if you won't get that error when you switch from Docker to using VirtualBox VMs? Or whether you should switch from using nginx to Apache? Always include a proper interrogative sentence in your posts. (I.e. not: "Any ideas?", but something like "With what can I replace nginx to get rid of this error?") Commented Jul 21, 2018 at 22:35

2 Answers 2

0

add user to your dockerfile which will execute the php binary for you something like:

....
RUN ["chmod", "+x", "/usr/bin/php"]
RUN ["chmod", "+x", "-R", "/var/log"]
EXPOSE 9000
RUN useradd -ms /bin/bash admin
USER admin
ENTRYPOINT ["/usr/bin/php"]
CMD ["--version"]
Sign up to request clarification or add additional context in comments.

10 Comments

You mean any user name would do or mine on my native os?
It will add a new user which which all the subsequent commands will be executed specifically the one in ENTRYPOINT and CMD. You may also give this new user elevated privileges by using -g and ` -G ` flag as per linux.die.net/man/8/useradd
It didn't work I'm afraid, still getting the same error when I try to docker-compose -up -d
I have updated the answer. Please check now. Add RUN ["chmod", "+x", "/usr/bin/php"]. Seems that your php binary is not have enough permission to run.
I did the changes you said, and after compose up I run docker ps which shows only the nginx container as active. I've run docker logs <nginx-cont-id> and get this 2018/07/21 19:45:40 [emerg] 1#1: host not found in upstream "php" in /etc/nginx/conf.d/default.conf:25 nginx: [emerg] host not found in upstream "php" in /etc/nginx/conf.d/default.conf:25`
|
0

RE:chat convo

However in your concern as to why the container stopped running.

If your command finishes executing the container will terminate If your command fails and the tty dies, the container will terminate.

In other words if your command never runs or runs and completes, as in your example

php -verson

is the code you are trying to run when that completes the container will terminate If you are not catching stdout you will never see this execute and the container will terminate as if nothing happened.

6 Comments

Not sure I've completely understand, but how do I keep the php container always active then? so when I run compose up all my containers keep running
ha yeah thats the hard part of docker containers. Your entrypoint should be a script or something. I dont use php, but I dont see people just running php the binary in docker typically you start off with an nginx container and launch nginx which will serve your php files nginx runs in the background and therefore will stay running until it crashes or is shutdown
Could you give me an example for the entrypoint even not in php, so at least I know roughly what to google for in php? Also all my containers (nginx, php, mysql, etc) are launching from the docker-compose.yml when I run the docker-compose up -d so nginx will launch first, is that right?
do you have a web/http server running on the docker container you have for php? i'm guessing no Are you using nginx as the web/http server or as a proxy? if web server, then I recommend you start off with just a NGINX docker container and try getting your php based site working there first docker pull nginx:latest then run it docker run -it -p9000:9000 8888:80 nginx:latest sh get this working first then worry about docker compose the docker compose file is to be used to make sure all supporting containers run together. you need to make your containers work first.
@Zee303 this is not a chat, nor a forum. This is a site for quality questions and answers. If you can't comment yet, that is for a reason. One thing you should refrain from is include comments about that ( "I cant join the chat" and "hope this helps, its hard when i cant be directly part of the discussion") in an answer (and that is not because there are 5 grammatical errors in those two sentences).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.