使用官方mysql docker镜像

使用官方mysql docker镜像

当尝试在 docker 容器中安装 mysql 5.7 时,出现以下错误。我是码头工人和容器的新手。

Step 16/23 : RUN apt-get install mysql-server-5.7
  ---> Running in 9624e9df68e7
 Reading package lists...
 Building dependency tree...
 Reading state information...
 Package mysql-server-5.7 is not available, but is referred to by another package.
 This may mean that the package is missing, has been obsoleted, or
 is only available from another source
 However the following packages replace it:
   mariadb-server-10.3
 E: Package 'mysql-server-5.7' has no installation candidate
 Service 'web' failed to build: The command '/bin/sh -c apt-get install mysql-server-5.7' returned a non-zero code: 100
 ERROR: Job failed: exit status 1

我的泊坞窗文件:

FROM ubuntu:latest
RUN DEBIAN_FRONTEND=noninteractive
RUN apt-get upgrade
RUN apt-get update
RUN apt-get install -y wget 
RUN wget http://archive.ubuntu.com/ubuntu/pool/main/m/mysql-5.7/mysql-server-5.7_5.7.21-1ubuntu1_amd64.deb
RUN apt-get install -y nodejs
RUN apt-get install -y npm
RUN apt-get install -y prometheus

RUN apt-get install -y openjdk-8-jdk
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
RUN sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list' 
RUN apt-get update 
RUN apt-get install -y elasticsearch
RUN apt-get install -y mongodb
RUN apt-get install mysql-server-5.7
RUN mkdir -p -v /data/db
WORKDIR /home/ubuntu/Github-MICROSERVICE/
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 6001
CMD chown -R mysql:mysql /var/lib/mysql \
&& service mysql start \
&& mysql -ppassword -e "CREATE DATABASE IF NOT EXISTS ted;GRANT ALL PRIVILEGES on ted.* TO 'root'@'localhost' WITH GRANT OPTION; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';FLUSH PRIVILEGES;SET GLOBAL connect_timeout=28800;SET GLOBAL sql_mode='NO_ENGINE_SUBSTITUTION';" \
&& service prometheus start \
&& service mongodb start\
&& npm start

答案1

您正尝试在新版本的 Ubuntu 上安装旧版本的 Mysql:

FROM ubuntu:latest

目前(2020 年 8 月)ubuntu:latest图像标签是 的同义词ubuntu:20.04。对于 Ubuntu 的每个新版本,这都会发生变化。具有 Mysql 5.7 的最后一个 Ubuntu 版本是 Ubuntu 18.04。看这里https://packages.ubuntu.com/bionic/mysql-server-5.7

您有几个选择:

使用官方mysql docker镜像

您可能根本不需要滚动自己的图像。从你的问题中还不清楚。所以你可以只运行一个带有 docker 镜像mysql:5.7甚至mysql:latest(8.0.21) 的容器。

使用较新版本的 mysql

只需将 dockerfile 更改为:

apt-get install mysql-server

这将安装适用于最新 Ubuntu 版本的最新 Mysql 版本。

使用旧版本的 ubuntu

将您的 docker 文件更改为:

FROM ubuntu:1804

相关内容