【发布时间】:2020-07-01 08:29:28
【问题描述】:
我有这个 docker 文件:
# Use the official image as a parent image
FROM mysql/mysql-server:8.0
# Set the working directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Copy the file from your host to your current location
COPY customers.sql .
COPY entrypoint.sh .
# Inform Docker that the container is listening on the specified port at runtime.
EXPOSE 1433:1433
# Run the command inside your image filesystem
RUN chmod +x entrypoint.sh
# Run the specified command within the container.
RUN /bin/bash ./entrypoint.sh
还有entypoint.sh:
mysql --host=localhost --protocol=tcp -u root -pMypassword -e "create database customersDatabase; use customersDatabase; source customers.sql;"
但我收到以下错误消息:
错误 2003 (HY000): 无法连接到 'localhost' (99) 上的 MySQL 服务器
当我运行 docker build 时
为了运行 docker 命令构建 entrypoint.sh 的正确方法是什么?
【问题讨论】:
-
您是否尝试在 docker 容器中运行 docker 容器?
-
是的,我正在尝试创建一个脚本来运行一个包含 mysql 实例的 docker 容器
-
我认为您正在尝试仅运行 mysql-server 实例,但是您正在尝试以与在计算机上作为 docker 容器运行相同的方式运行它,这显然行不通。你创建这个 Dockerfile 的目的是什么?
-
我的目标是创建一个运行mysql实例的docker文件并将一个数据库,sql文件导入mysql数据库。
-
在没有 Docker 的情况下执行此操作。在您的主机上运行 shell 脚本。在 Docker 中打包它的机制有点复杂,而且由于您将立即“逃逸”回针对主机 Docker 套接字运行命令,因此在 Docker 中执行此操作并没有真正获得任何好处。