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;
}
}
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"]
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.