php - Dockerfile Image 命令 '/bin/sh -c apt-get install -y mysqld-server' 返回非零代码 : 100

标签 php mysql ubuntu docker nginx

我想用这个规范制作一个 Docker 镜像:

  1. Ubuntu:16.04/最新
  2. PHP 7.x
  3. nginx:最新的 mySQL 5.x
  4. 公开端口 80 和 443
  5. 目录/来源

可选:

  1. VIM
  2. PHP Composer

我的 Dockerfile:

# Download base image ubuntu 16.04
FROM ubuntu:16.04

# Update Ubuntu Software repository
RUN apt-get update

# Install PHP, nginx, mySQL
RUN apt-get install -y nginx php7.0-fpm && \
rm -rf /var/lib/apt/lists/*

# Install MySQL and set default root password
RUN echo 'mysql-server mysql-server/root_password  password mypassword' | debconf-set-selections
RUN echo 'mysql-server mysql-server/root_password_again password mypassword' | debconf-set-selections
RUN apt-get install -y mysql-server

# Define the ENV variable
ENV nginx_vhost /etc/nginx/sites-available/default
ENV php_conf /etc/php/7.0/fpm/php.ini
ENV nginx_conf /etc/nginx/nginx.conf

# Enable php-fpm on nginx virtualhost configuration
COPY default ${nginx_vhost}
RUN sed -i -e 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' ${php_conf} && \
echo "\ndaemon off;" >> ${nginx_conf}

RUN mkdir -p /run/php && \
chown -R www-data:www-data /var/www/html && \
chown -R www-data:www-data /run/php

# Volume configuration
VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx", "/var/www/html"]

# Configure Services and Port
COPY start.sh /start.sh
CMD ["./start.sh"]

EXPOSE 80 443

我在构建时收到此错误消息

Sending build context to Docker daemon 5.632 kB
Step 1 : FROM ubuntu:16.04
 ---> 2d696327ab2e
Step 2 : RUN apt-get update
 ---> Using cache
 ---> b58709c2b7b9
Step 3 : RUN apt-get install -y nginx php7.0-fpm &&     rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> 3d58b4fac924
Step 4 : RUN echo 'mysql-server mysql-server/root_password  password mypassword' | debconf-set-selections
 ---> Using cache
 ---> 85256efe3bd3
Step 5 : RUN echo 'mysql-server mysql-server/root_password_again password mypassword' | debconf-set-selections
 ---> Using cache
 ---> d1f71eeacbe2
Step 6 : RUN apt-get install -y mysqld-server
 ---> Running in 9dba6ce0c59a
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package mysqld-server
The command '/bin/sh -c apt-get install -y mysqld-server' returned a non-zero code: 100

如何修复它?

谢谢

最佳答案

您的问题出在rm -rf/var/lib/apt/lists/*行上。您将删除 apt-get update 已获取的列表。然后您尝试使用 apt 安装软件包。这将会失败。

您需要将 rm -rf/var/lib/apt/lists/移动到安装 mysql-server 的行之后。

# Download base image ubuntu 16.04
FROM ubuntu:16.04

# Update Ubuntu Software repository
RUN apt-get update

# Install PHP, nginx, mySQL
RUN apt-get install -y nginx php7.0-fpm

# Install MySQL and set default root password
RUN echo 'mysql-server mysql-server/root_password  password mypassword' | debconf-set-selections
RUN echo 'mysql-server mysql-server/root_password_again password mypassword' | debconf-set-selections
RUN apt-get install -y mysql-server && rm -rf /var/lib/apt/lists/*

# Define the ENV variable
ENV nginx_vhost /etc/nginx/sites-available/default
ENV php_conf /etc/php/7.0/fpm/php.ini
ENV nginx_conf /etc/nginx/nginx.conf

# Enable php-fpm on nginx virtualhost configuration
COPY default ${nginx_vhost}
RUN sed -i -e 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' ${php_conf} && \
echo "\ndaemon off;" >> ${nginx_conf}

RUN mkdir -p /run/php && \
chown -R www-data:www-data /var/www/html && \
chown -R www-data:www-data /run/php

# Volume configuration
VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx", "/var/www/html"]

# Configure Services and Port
COPY start.sh /start.sh
CMD ["./start.sh"]

关于php - Dockerfile Image 命令 '/bin/sh -c apt-get install -y mysqld-server' 返回非零代码 : 100,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46315587/

相关文章:

php - 从另一个表 MySQL 获取名称

php - 字符集编码 PHP/MySQL

php - 用于测量请求速度和数据库速度的工具

mysql - 从带有 "effective date"的表构建每日 View

linux - random() 在 Linux 中函数相同的值(同时 grof ing)

ubuntu - 我可以在 Ubuntu 虚拟机上安装应用程序吗?

php - 使用 PHP 页面在远程 Linux 服务器上执行已安装的软件命令

php - Laravel 集合过滤以避免空记录

MySQL 从多条记录中仅选择具有第一个和最后一个日期的记录

linux - huponexit 关闭并输入 & 符号 - 但程序仍然关闭