所以我有一个不和谐,但我目前在家里的服务器上运行它。我现在决定从头开始设置服务器。现在我在服务器上有MySQL和程序(不在docker容器中),我现在想把它做成Docker化。
为了简单起见,我决定只扩展MySQL容器,但我不断遇到错误。现在一切都可以正常工作,除了程序没有连接到MySQL服务器。
我尝试使用以下命令启动应用程序
CMD ./PokeBot
结果是连接被拒绝错误。首先,我试图公开端口3306并用作MySQL服务器的IP。没有任何效果。127.0.0.1
然后我认为MySQL服务器没有运行,所以我创建了一个Bash Shell脚本()来启动MySQL服务器,但是我得到了错误。.shFatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
我该怎么做才能在Docker容器中与MySQL一起运行该程序?
我启动容器的命令是:
docker run -p 3306:3306 name
项目结构:
这是我的 Dockerfile:
FROM mysql:latest as builder
# That file does the DB initialization but also runs mysql daemon, by removing the last line it will only init
RUN ["sed", "-i", "s/exec \"$@\"/echo \"not running $@\"/", "/usr/local/bin/docker-entrypoint.sh"]
# needed for intialization
ENV MYSQL_ROOT_PASSWORD=asdfghjkl
COPY setup.sql /docker-entrypoint-initdb.d/
ADD ca-certificates.crt /etc/ssl/certs/
# Need to change the datadir to something else that /var/lib/mysql because the parent docker file defines it as a volume.
# https://docs.docker.com/engine/reference/builder/#volume :
# Changing the volume from within the Dockerfile: If any build steps change the data within the volume after
# it has been declared, those changes will be discarded.
RUN ["/usr/local/bin/docker-entrypoint.sh", "mysqld", "--datadir", "/initialized-db"]
FROM mysql:latest
ENV MYSQL_ROOT_PASSWORD=asdfghjkl
ADD ca-certificates.crt /etc/ssl/certs/
COPY PokeBot /
COPY --from=builder /initialized-db /var/lib/mysql
COPY start.sh /
EXPOSE 3306
RUN apt update
RUN apt install ca-certificates sudo -y
RUN update-ca-certificates
CMD ./start.sh
青春有我
相关分类