Docker构建Laravel环境报错:无法定位mysql-client包
It looks like you’re hitting a couple of common pitfalls with your Dockerfile command. Let’s break down the issues and fix them:
1. Fix the Typo in the Command Flag
The most probable cause here is a typographical error in the --no-install-recommends flag. It seems you’ve accidentally used an em dash (—) instead of two regular hyphens (--). The shell interprets the em dash as part of the package name, which is why apt-get can’t find a package called mysql-client —-no-install-recommends.
Update your Dockerfile line to use proper double hyphens:
RUN apt-get update && apt-get install -y mysql-client --no-install-recommends && docker-php-ext-install pdo_mysql
2. Use the Correct Package Name (If Needed)
If fixing the typo doesn’t resolve the issue, the problem might be that the mysql-client package isn’t available under that name in your base image’s repository. For newer Debian/Ubuntu-based images, the official MySQL client is often provided via the default-mysql-client package instead.
Modify the command to use this package name:
RUN apt-get update && apt-get install -y default-mysql-client --no-install-recommends && docker-php-ext-install pdo_mysql
3. Optional: Clean Up to Reduce Image Size
To keep your Docker image lean, you can add commands to clean up the apt cache after installation (this helps avoid unnecessary bloat):
RUN apt-get update && \ apt-get install -y default-mysql-client --no-install-recommends && \ docker-php-ext-install pdo_mysql && \ apt-get clean && \ rm -rf /var/lib/apt/lists/*
After making these changes, rebuild your image with docker-compose build --no-cache and then run docker-compose up again. That should resolve the package-not-found error.
内容的提问来源于stack exchange,提问作者aasanchez

