Home > Net >  Run php command inside bash script inside Docker container with ubuntu image
Run php command inside bash script inside Docker container with ubuntu image

Time:05-18

I have a bash script and a php script.

--------EDIT-------- I SOLVED IT, I AM JUST STUPID, I WROTE MY ANSWER BELOW.

(I can put code screenshots if you want.)

MY DOCKERFILE:

ARG VERSION=latest
FROM ubuntu:bionic
RUN apt-get -y update && apt-get -y upgrade
COPY ./resources/ start.sh /sandbox/
WORKDIR /sandbox/
ENTRYPOINT ["sh","start.sh"]

I want to execute them in a docker container as i said in the title.

The 'entry point' of the docker container is the bash script.

Inside the bash script i have a line

php PHP_SCRIPT.php

But when i execute, it gives me the error:

PHP_SCRIPT.php: php: not found

or something like that

i saw that the php command usually resides in '/usr/bin/php', but i tried to run the command 'which php' in the docker container and the result was '/usr/local/bin/php'

Maybe i am calling the php command wrong?

But the result that i want is to run a php script INSIDE a bash script that starts when i start the docker container.

CodePudding user response:

You are using the docker image FROM ubuntu:bionic which does not have PHP installed by default. Try FROM php (or one of the many tags available) instead.

CodePudding user response:

the problem is that PHP is not installed in your container To do this, you can use your official PHP image https://hub.docker.com/_/php

FROM php:7.4-cli

ARG VERSION=latest
RUN apt-get -y update && apt-get -y upgrade
COPY ./resources/ start.sh /sandbox/
WORKDIR /sandbox/
ENTRYPOINT ["sh","start.sh"]

CodePudding user response:

FROM php:7.4-cli
WORKDIR /opt/myapp
COPY myshellscript.sh .
COPY myphpscript.php .
ENTRYPOINT ["./myshellscript.sh"]


$ docker build -t my-image .
$ docker run --rm --name my-app my-image
call php from shellscript
output from php script
sleeping ...

CodePudding user response:

And i would get the "php not found error" because i didnt install php to the docker container.

So, I tried writing in the dockerfile

RUN apt-get php-cli (i also tried with php:cli and seemed to have same effect),

to try to install php to container, but when i would start container it would seem like it would freeze and not do anything.

Apparenty, it doesnt 'freeze', but i only had to wait for the php to update in the container. :D

  • Related