You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker Stack执行Doctrine迁移及Symfony命令遇entrypoint.sh未找到问题

Alright, let's tackle that "entrypoint.sh not found" error you're hitting with your PHP-FPM container. This is a super common snag when setting up custom entrypoints, so let's break down the most likely fixes step by step:

1. First, make sure you're copying the entrypoint into the container

If your Dockerfile doesn't explicitly copy entrypoint.sh into the container image, the runtime will never find it. Double-check that you have a COPY directive pointing to the file (since it's in the same directory as your Dockerfile, the source path is straightforward):

# Copy the entrypoint script to a directory in the container's PATH (like /usr/local/bin)
COPY entrypoint.sh /usr/local/bin/

2. Fix file permissions (this is critical!)

Even if you copy the file, if it doesn't have execute permissions, Docker will throw a "not found" error (the message is a bit misleading here, but it's usually permission-related). You can set permissions in two ways:

  • Add a RUN command to make it executable:
    RUN chmod +x /usr/local/bin/entrypoint.sh
    
  • Or combine the copy and permission step to reduce image layers:
    COPY --chmod=755 entrypoint.sh /usr/local/bin/
    

3. Verify your ENTRYPOINT directive uses the correct path

Always use an absolute path for your entrypoint to avoid issues with the container's PATH variable. For example:

# Exec format (recommended, preserves signal handling like Ctrl+C)
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# Don't forget to keep the default PHP-FPM command at the end
CMD ["php-fpm"]

If you use the shell format (ENTRYPOINT entrypoint.sh), ensure the script's directory is in the container's PATH—but absolute paths are always safer.

4. Fix line endings (Windows users, this is a gotcha!)

If you edited entrypoint.sh on Windows, it likely uses CRLF line endings instead of Linux's LF. The container will try to run entrypoint.sh\r (with a hidden carriage return), which doesn't exist. Fix this by:

  • Switching your editor to use LF line endings (e.g., in VS Code, click the CRLF indicator in the bottom right and select LF)
  • Or adding a line to your Dockerfile to convert endings:
    RUN sed -i 's/\r$//' /usr/local/bin/entrypoint.sh
    

5. Ensure your entrypoint has a valid shebang

The first line of entrypoint.sh needs to tell the container which shell to use to execute it. For basic scripts, use:

#!/bin/sh

If you're using bash-specific features, use #!/bin/bash instead. Without this line, the container won't know how to run the script.

Example working setup

Here's a complete Dockerfile that ties all these fixes together:

FROM php:8.2-fpm

# Set working directory for your Symfony app
WORKDIR /var/www/html

# Copy entrypoint with correct permissions
COPY --chmod=755 entrypoint.sh /usr/local/bin/

# Install required PHP extensions (adjust for your Symfony/Doctrine needs)
RUN docker-php-ext-install pdo_mysql

# Set entrypoint and default command
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["php-fpm"]

And a sample entrypoint.sh with your desired commands (plus a wait for MySQL to be ready):

#!/bin/sh

# Wait for MySQL to be accessible (adjust credentials to match your stack)
until mysqladmin ping -h"mysql" -u"db_user" -p"db_password" --silent; do
    echo "Waiting for MySQL to start..."
    sleep 2
done

# Run Doctrine migrations
php bin/console doctrine:migrations:migrate --no-interaction

# Clear Symfony cache
php bin/console cache:clear

# Execute the default CMD (php-fpm)
exec "$@"

Quick debugging tip

If you're still stuck, run docker exec -it <your_php_container_name> bash to shell into the container. Check if entrypoint.sh exists at the path you specified, and run ls -l /usr/local/bin/entrypoint.sh to verify permissions.

内容的提问来源于stack exchange,提问作者NucleusXorg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 06:56:00