duan246558 2018-02-14 22:12
浏览 729

用于PHP-CLI执行的最小Docker镜像

I want to run a php script as a oneliner from the command line. Since on this linux machine no PHP is installed but Docker I thought about executing the PHP interpreter by running an little PHP Docker image which executing the script and deletes the container and image after finishing.

My internet connection is not fast and thus the image should be as small as possible.

The script process.php should read the File data.json in the current working directory and generate some text files in subdirectories. So no special PHP modules are required.

My questions:

  • Which small/minimal ready-to-use-image on Dockerhub is recommended?
  • How small is this image?
  • How to write the one liner docker run ... to be executed on the Linux command line (bash)?

My research on Dockerhub resulted in tons of PHP images with full blown PHP and not optimized on Host volume modifications as a one liner.

  • 写回答

1条回答 默认 最新

  • douyou1937 2018-02-15 00:11
    关注

    Found a solution close to what I need.

    The script process.php:

    <?php
    echo "hello";
    $data = json_decode(file_get_contents(__DIR__."/data.json"),true);
    file_put_contents("message.txt","message is ".$data["message"]);
    

    The data file data.json:

    {
        "message": "hello world"
    }
    

    The one-liner:

    $ docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp \ 
    php:7.2.2-cli-alpine3.6 php process.php
    

    And the result is message.txt:

    message is hello world
    

    Not the smallest image, but has a size of 62 MB and removes itself after finishing.

    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示