简体   繁体   中英

Docker - Installing Composer /bin/sh: 1: php: not found curl: (23) Failed writing body (0 != 16133)

Hello I am creating a dockerfile for my laravel project. This is it so far:

FROM php:7.2-cli
FROM nginx
FROM node:8
MAINTAINER zachary tyhacz

# does not install mysql
# mysql is outside container

RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

WORKDIR /var/www/public
COPY . /var/www/public

COPY nginx.conf /etc/nginx/sites-available/domain
RUN ln -s /etc/nginx/sites-available /etc/nginx/sites-enabled

RUN npm install
RUN composer install

# sets up the database
CMD php artisan migrate:fresh --seed

# resets configuration files
CMD php artisan config:cache

# refreshes routes
CMD php artisan route:cache

# enables serve
CMD php artisan serve --host=0.0.0.0 --port=436

EXPOSE 8080/udp
EXPOSE 8080/tcp
EXPOSE 80/udp
EXPOSE 80/tcp
EXPOSE 436/tcp
EXPOSE 436/udp

upon docker tag to create an image, it gets to this instruction:

Step 6/22 : RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

and it throws this error and stops.

/bin/sh: 1: php: not found
curl: (23) Failed writing body (0 != 16133)

I am not sure what is going wrong. I think it could be a permissions issue or a directory issue.

Thanks anyone for any suggestions in helping me out

also, my reference in helping me create this dockerfile is this: https://buddy.works/guides/laravel-in-docker

You can only have one base image using FROM in a Dockerfile. Basically, that tells docker what to start with. In your case, you have several FROM s, so it appears that Docker simply takes the last one you give it, in this case node:8 . So PHP is never being installed.

To fix this issue, you'll need to pick a single base image (for example php), and install your other dependencies on top of that, so you could manually install nginx and node on top of the php image using RUN . You may also want to consider building a separate nginx image. This is considered good practice to separate your services into different images when possible.

Also, instead of using multiple CMD entries, use a small startup shell script. For example

#!/usr/bin/env bash
set -e
php artisan migrate:fresh --seed
php artisan config:cache
php artisan route:cache
exec php artisan serve --host=0.0.0.0 --port=436

Put that in a script called start.sh or something like that, then in your Dockerfile, use

CMD ["./start.sh"]

Then, you'll probably also want to start a second container for your nginx service. You could do this manually using docker run, but I suggest checking out docker-compose. It helps you build and run multiple containers at once.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM