“没有这样的文件或目录”当运行Docker镜像

问题描述:

我是新来的Docker,并尝试在centos 6上创建一个拥有owncloud 7的映像。 我创建了一个Dockerfile。我已经建立了一个图像。 一切顺利,只是权当我运行图像:“没有这样的文件或目录”当运行Docker镜像

docker run -i -t -d -p 80:80 vfoury/owncloud7:v3 

我得到的错误:

Cannot start container a7efd9be6a225c19089a0f5a5c92f53c4dd1887e8cf26277d3289936e0133c69: 
exec: "/etc/init.d/mysqld start && /etc/init.d/httpd start": 
stat /etc/init.d/mysqld start && /etc/init.d/httpd start: no such file or directory 

如果我运行/ bin中的图像/ bash的

docker run -i -t -p 80:80 vfoury/owncloud7:v3 /bin/bash 

然后我可以运行命令

/etc/init.d/mysqld start && /etc/init.d/httpd start 
它的工作原理是

这里是我的Dockerfile内容:

# use the centos6 base image 
FROM centos:centos6 
MAINTAINER Vincent Foury 
RUN yum -y update 
# Install SSH server 
RUN yum install -y openssh-server 
RUN mkdir -p /var/run/sshd 
# add epel repository 
RUN yum install epel-release -y 
# install owncloud 7 
RUN yum install owncloud -y 
# Expose les ports 22 et 80 pour les rendre accessible depuis l'hote 
EXPOSE 22 80 
# Modif owncloud conf to allow any client to access 
COPY owncloud.conf /etc/httpd/conf.d/owncloud.conf 
# start httpd and mysql 
CMD ["/etc/init.d/mysqld start && /etc/init.d/httpd start"] 

任何帮助,将不胜感激

文森特F.

多次测试后,这里是工程安装ouwncloud(不包括MySQL的)的Dockerfile:

# use the centos6 base image 
FROM centos:centos6 

RUN yum -y update 

# add epel repository 
RUN yum install epel-release -y 

# install owncloud 7 
RUN yum install owncloud -y 

EXPOSE 80 

# Modif owncloud conf to allow any client to access 
COPY owncloud.conf /etc/httpd/conf.d/owncloud.conf 

# start httpd 
CMD ["/usr/sbin/apachectl","-D","FOREGROUND"] 

然后

docker build -t <myname>/owncloud 

然后

docker run -i -t -p 80:80 -d <myname>/owncloud 

,那么你应该能够打开

http://localhost/owncloud 

在浏览器

我想这是因为你想在Dockerfile CMD内使用&&指令。

如果您打算在Docker容器中运行多个服务,您可能需要检查Supervisor。它使您能够在容器中运行多个守护进程。检查Docker文档https://docs.docker.com/articles/using_supervisord/

或者,您可以用ADD一个简单的bash脚本来启动两个守护进程,然后将CMD设置为使用您添加的bash文件。

+0

谢谢你的回复。我试着只启动httpd来检查它是否会在没有&&的情况下运行。但我得到同样的问题。我在boot2docker的mac上,可能是问题的一部分吗? – 2014-10-09 19:01:26

+0

那么你开始的脚本(在init.d中)只启动Apache进程,然后退出。你需要它在前台运行。 – 2014-10-10 07:04:23

+0

如果我没有错,根据我在这里阅读的内容:[link](https://docs.docker.com/userguide/dockerizing/),RUN命令的-d参数启动一个容器作为deamon。我错了吗 ?所以我认为使用-d运行映像会启动并永不停止,直到我发送一个“docker stop”命令。 – 2014-10-10 13:42:25

的问题是,你的CMD参数包含shell操作,但你使用CMD的EXEC形式代替壳形式。 exec-form将参数传递给其中一个exec函数,这将不会解释shell操作。 shell形式将参数传递给sh -c

更换

CMD ["/etc/init.d/mysqld start && /etc/init.d/httpd start"] 

CMD /etc/init.d/mysqld start && /etc/init.d/httpd start 

CMD ["sh", "-c", "/etc/init.d/mysqld start && /etc/init.d/httpd start"] 

https://docs.docker.com/reference/builder/#cmd