我对码头很陌生。
我伪造了我的Laravel申请。这是基本图像php:8.1.2-apache
在Dockerfile的末尾,我使用了自己的入口点脚本
ENTRYPOINT ["/usr/local/bin/start"]此脚本(/usr/local/bin/start)包含以下几个命令:
composer install --no-interaction &&
php artisan config:cache &&
php artisan route:cache &&
php artisan view:cache &&
php artisan storage:link现在我用这个Docker映像来做很多事情,比如laravel调度器,队列等等.
我想要做的是从坞-撰写文件中扩展入口点脚本,以便每当容器启动时,首先执行入口点脚本,最后执行从docker传递的主命令。
类似于:
laravel-scheduler:
image: laravel
container_name: laravel-scheduler
restart: always
volumes:
- .:/var/www/html
command: php artisan schedule:work发布于 2022-05-15 16:40:01
First
您可以创建build_entrypoint.sh
#!/bin/bash
composer install --no-interaction &&
php artisan config:cache &&
php artisan route:cache &&
php artisan view:cache &&
php artisan storage:link并在基本Dockerfile中使用它ENTRYPOINT ["./build_entrypoint.sh"]
在停靠-撰写中,您可以重写以下行为:在命令部分,手动启动/build_entrypoint.sh +扩展命令
有点像command: /bin/sh -c "./build_entrypoint.sh && ./test_running.sh"
。
第二:漂亮的
在docker中启动一个新服务--根据主php映像与守护进程进行组合。
docker/php/Dockerfile
FROM php:8.1-fpm
# ... others commands (setup composer and php-ext(s))
# Attention! We run this command to build our image
RUN composer install --no-interaction &&
php artisan config:cache &&
php artisan route:cache &&
php artisan view:cache &&
php artisan storage:linkdocker-compose.yml
# Main php service
php:
build:
context: docker/php # path to your dockerfile
volumes:
- .:/var/www/html
# PHP WORKER service with daemon work
php-worker:
build:
context: docker/php # path to your dockerfile
volumes:
- .:/var/www/html
command: php artisan schedule:work发布于 2022-05-16 00:13:53
只需使用exec "$@"结束入口点脚本即可。它将以您所描述的方式来尊重撰写command:。
#!/bin/sh
# Do first-time setup steps that can't be done in the Dockerfile
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan storage:link
# Run the main container command
exec "$@"还请参阅Dockerfile文档中的了解CMD和入口点是如何相互作用的:CMD (或撰写command:覆盖)作为参数传递给您的入口点脚本。exec "$@"调用是一个shell命令,它用这些命令行参数替换当前的shell。
另一个重要的警告是,在Dockerfile中,ENTRYPOINT必须是JSON数组exec格式。如果它是裸字符串shell形式,则外壳包装会阻止它工作。你在问题中显示的语法是正确的。
https://stackoverflow.com/questions/72250096
复制相似问题