dongyan0629 2017-09-20 07:18
浏览 884

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

I want to make a docker image with this spec:

  1. Ubuntu : 16.04 / Latest
  2. PHP 7.x
  3. nginx : Latest mySQL 5.x
  4. Expose Port 80 & 443
  5. Directory / Source

Optional :

  1. VIM
  2. PHP Composer

My 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 "
daemon 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

I get this error message when I built it

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

How can I fix it?

Thanks

  • 写回答

1条回答 默认 最新

  • dosc9472 2017-09-20 08:09
    关注

    Your problem is with the line rm -rf /var/lib/apt/lists/*. You are deleting the lists that have been fetched by the apt-get update. You then try to install a package using apt. This will fail.

    You need to move rm -rf /var/lib/apt/lists/ after the line that installs 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 "
    daemon 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"]
    
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样