简体   繁体   English

Docker无法启动没有此类文件或目录的容器

[英]Docker cannot start container no such file or directory

I'm unable to start my container after build and I got : 构建后,我无法启动容器,我得到了:

Error response from daemon: Cannot start container ogc-mysql: no such file or directory
Error: failed to start one or more containers

Here is my Docker file : 这是我的Docker文件:

FROM ubuntu:latest

MAINTAINER Davin Kevin

# Install latest updates
RUN apt-get update
RUN apt-get upgrade -y

# Install mysql client and server
RUN apt-get -y install mysql-client mysql-server curl

# Enable remote access (default is localhost only, we change this
# otherwise our database would not be reachable from outside the container)
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf

# Install database
ADD ./database.sql /var/db/database.sql

# Set Standard settings
ENV user ogc
ENV password ogc
ENV url file:/var/db/database.sql
ENV right READ

# Install starting script
ADD ./start-database.sh /usr/local/bin/start-database.sh
RUN chmod +x /usr/local/bin/start-database.sh

EXPOSE 3306

CMD ["/usr/local/bin/start-database.sh"]

And my sh script only does : 而我的sh脚本只做:

docker build -t ogc-mysql .
docker run --name ogc-mysql -d -p 3306:3306 ogc-mysql

And reffering to the Docker documentation : 并参考Docker文档:

docker build will return a no such file or directory error if the file or directory does not exist in the uploaded context. 如果文件或目录在上传的上下文中不存在,则docker build将不返回此类文件或目录错误。 This may happen if there is no context, or if you specify a file that is elsewhere on the Host system. 如果没有上下文,或者您指定了主机系统上其他位置的文件,则可能会发生这种情况。 The context is limited to the current directory (and its children) for security reasons, and to ensure repeatable builds on remote Docker hosts. 出于安全原因,上下文仅限于当前目录(及其子目录),并确保在远程Docker主机上可重复的构建。 This is also the reason why ADD ../file will not work. 这也是ADD ../file无法工作的原因。

This command : docker ps -a returns : 此命令: docker ps -a返回:

CONTAINER ID : 70..
IMAGE : ogc-sql:latest
COMMAND : "/usr/local/bin/star"
CREATED : 13 seconds ago
STATUS : /
PORTS : /
NAMES : ogc-mysql

The fact is that this command works successfully on Mac OS.. 事实是此命令在Mac OS上可以成功运行。

I got this when integrating and invoking a shell script using CMD which had Windows line breaks (CR+LF) in my container. 当使用CMD集成和调用Shell脚本时,在容器中有Windows换行符(CR + LF)时,出现了此错误。

After converting to Linux line endings (LF only) and rebuilding the container, it would start just fine. 转换为Linux行尾(仅适用于LF)并重建容器后,它将开始正常。

The docker run syntax is from https://docs.docker.com/reference/commandline/cli/#run docker运行语法来自https://docs.docker.com/reference/commandline/cli/#run

docker run [OPTIONS] IMAGE [COMMAND] [ARG...] 泊坞窗运行[选项]图像[命令] [ARG ...]

as ogc-mysql is not an image or a command, this fails 由于ogc-mysql不是映像或命令,因此失败

can you post the result of 你可以发布结果吗

docker ps -a 

问题已解决,这是sh文件中的一个行尾问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM