简体   繁体   English

使用 ubuntu 映像在 Docker 容器内的 bash 脚本中运行 php 命令

[英]Run php command inside bash script inside Docker container with ubuntu image

I have a bash script and a php script.我有一个 bash 脚本和一个 php 脚本。

--------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.正如我在标题中所说,我想在 docker 容器中执行它们。

The 'entry point' of the docker container is the bash script. docker 容器的“入口点”是 bash 脚本。

Inside the bash script i have a line在bash脚本里面我有一行

php PHP_SCRIPT.php

But when i execute, it gives me the error:但是当我执行时,它给了我错误:

PHP_SCRIPT.php: php: not found PHP_SCRIPT.php: php: 未找到

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'我看到 php 命令通常驻留在“/usr/bin/php”中,但我尝试在 docker 容器中运行命令“which php”,结果是“/usr/local/bin/php”

Maybe i am calling the php command wrong?也许我错误地调用了 php 命令?

But the result that i want is to run a php script INSIDE a bash script that starts when i start the docker container.但我想要的结果是在我启动 docker 容器时启动的 bash 脚本内运行 php 脚本。

You are using the docker image FROM ubuntu:bionic which does not have PHP installed by default.您正在使用FROM ubuntu:bionic的 docker 映像,默认情况下没有安装 PHP。 Try FROM php (or one of the many tags available ) instead.尝试FROM php (或可用的众多标签之一)。

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问题是你的容器中没有安装 PHP 要做到这一点,你可以使用你的官方 PHP 镜像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"]

And i would get the "php not found error" because i didnt install php to the docker container.而且我会收到“找不到 php 错误”,因为我没有将 php 安装到 docker 容器中。

So, I tried writing in the dockerfile所以,我试着写在 dockerfile

RUN apt-get php-cli (i also tried with php:cli and seemed to have same effect), RUN apt-get php-cli (我也尝试使用 php:cli 并且似乎具有相同的效果),

to try to install php to container, but when i would start container it would seem like it would freeze and not do anything.尝试将 php 安装到容器,但是当我启动容器时,它似乎会冻结并且不执行任何操作。

Apparenty, it doesnt 'freeze', but i only had to wait for the php to update in the container.显然,它不会“冻结”,但我只需要等待 php 在容器中更新。 :D :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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