使用 docker 恢复旧的 php 5.6 网站

问题描述 投票:0回答:1

我正在恢复一个仍使用 PHP5.6 和 mysql_connect 的旧网站,以更新其代码。

我打算使用 PHP 5.6 设置一个 docker 环境,以确保一切正常,然后再进行急需的更新。

但是我在安装 mysql 驱动程序时遇到了困难。

这是我的 docker-compose.yml

version: '3'

services:
  db:
    image: mysql:5.5
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: "edited for privacy"
      MYSQL_DATABASE: "edited for privacy"
      MYSQL_USER: "edited for privacy"
      MYSQL_PASSWORD: "edited for privacy"

  php:
    depends_on:
      - db
    build: .
    volumes:
      - ./:/var/www/html
    ports:
      - "8000:80"
    restart: always

volumes:
  db_data: {}

使用第一个 dockerfile,我遇到以下错误

FROM php:5.6-apache

RUN apt-get install mysql-server mysql-client php5-mysql

RUN a2enmod rewrite
docker compose up -d
[+] Building 1.2s (6/7)
 => [internal] load build definition from Dockerfile                                                                                                                                                                                   0.0s
 => => transferring dockerfile: 139B                                                                                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/php:5.6-apache                                                                                                                                                                      0.8s
 => [auth] library/php:pull token for registry-1.docker.io                                                                                                                                                                             0.0s
 => CACHED [1/3] FROM docker.io/library/php:5.6-apache@sha256:0a40fd273961b99d8afe69a61a68c73c04bc0caa9de384d3b2dd9e7986eec86d                                                                                                         0.0s
 => => resolve docker.io/library/php:5.6-apache@sha256:0a40fd273961b99d8afe69a61a68c73c04bc0caa9de384d3b2dd9e7986eec86d                                                                                                                0.0s
 => ERROR [2/3] RUN apt-get install mysql-server mysql-client php5-mysql                                                                                                                                                               0.3s
------
 > [2/3] RUN apt-get install mysql-server mysql-client php5-mysql:
#0 0.292 Reading package lists...
#0 0.296 Building dependency tree...
#0 0.296 Reading state information...
#0 0.297 E: Unable to locate package mysql-server
#0 0.297 E: Unable to locate package mysql-client
#0 0.297 E: Unable to locate package php5-mysql
------
failed to solve: executor failed running [/bin/sh -c apt-get install mysql-server mysql-client php5-mysql]: exit code: 100

我以为我必须先更新,但后来我遇到了这个错误,我不知道该怎么办。

FROM php:5.6-apache

RUN apt-get update && apt-get install -y \
    mysql-client \
    mysql-server \
    php5-mysql

RUN a2enmod rewrite
docker compose up -d
[+] Building 0.7s (5/6)
 => [internal] load build definition from Dockerfile                                                                                                                                                                                   0.0s
 => => transferring dockerfile: 189B                                                                                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/php:5.6-apache                                                                                                                                                                      0.4s
 => CACHED [1/3] FROM docker.io/library/php:5.6-apache@sha256:0a40fd273961b99d8afe69a61a68c73c04bc0caa9de384d3b2dd9e7986eec86d                                                                                                         0.0s
 => => resolve docker.io/library/php:5.6-apache@sha256:0a40fd273961b99d8afe69a61a68c73c04bc0caa9de384d3b2dd9e7986eec86d                                                                                                                0.0s
 => ERROR [2/3] RUN su apt-get update -q && apt-get install -y     mysql-client     mysql-server     php5-mysql                                                                                                                        0.3s
------
 > [2/3] RUN su apt-get update -q && apt-get install -y     mysql-client     mysql-server     php5-mysql:
#0 0.281 su: invalid option -- 'q'
#0 0.281 Usage: su [options] [LOGIN]
#0 0.281
#0 0.281 Options:
#0 0.281   -c, --command COMMAND         pass COMMAND to the invoked shell
#0 0.281   -h, --help                    display this help message and exit
#0 0.281   -, -l, --login                make the shell a login shell
#0 0.281   -m, -p,
#0 0.281   --preserve-environment        do not reset environment variables, and
#0 0.281                                 keep the same shell
#0 0.281   -s, --shell SHELL             use SHELL instead of the default in passwd
#0 0.281
------
failed to solve: executor failed running [/bin/sh -c su apt-get update -q && apt-get install -y     mysql-client     mysql-server     php5-mysql]: exit code: 2

我不知道下一步该怎么做,非常欢迎任何帮助。

mysql docker php-5.6
1个回答
0
投票

从上面的错误消息来看,不支持命令“q”参数。您可以按照建议尝试使用选项 -c / -p 等

0 0.281 su: invalid option -- 'q'

0 0.281 Options:
#0 0.281   -c, --command COMMAND         pass COMMAND to the invoked shell
#0 0.281   -h, --help                    display this help message and exit
#0 0.281   -, -l, --login                make the shell a login shell
#0 0.281   -m, -p,
#0 0.281   --preserve-environment        do not reset environment variables, and
#0 0.281                                 keep the same shell
#0 0.281   -s, --shell SHELL             use SHELL instead of the default in passwd
© www.soinside.com 2019 - 2024. All rights reserved.