Apache 运行Docker映像时“无此类文件或目录”
我是Docker的新手,尝试在centos 6上使用owncloud 7创建图像。 我已经创建了一个Dockerfile。我已经建立了一个形象。 一切正常,除了运行图像时:Apache 运行Docker映像时“无此类文件或目录”,apache,build,docker,Apache,Build,Docker,我是Docker的新手,尝试在centos 6上使用owncloud 7创建图像。 我已经创建了一个Dockerfile。我已经建立了一个形象。 一切正常,除了运行图像时: docker run -i -t -d -p 80:80 vfoury/owncloud7:v3 我得到一个错误: Cannot start container a7efd9be6a225c19089a0f5a5c92f53c4dd1887e8cf26277d3289936e0133c69: exec: "/etc/i
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"]
任何帮助都将不胜感激
Vincent F.我认为这是因为您试图在Dockerfile CMD指令中使用&& 如果要在Docker容器中运行多个服务,可能需要检查Supervisor。它使您能够在容器中运行多个守护进程。查看Docker文档,网址为
或者,您可以添加一个简单的bash脚本来启动两个守护进程,然后将CMD设置为使用您添加的bash文件。我认为这是因为您试图在Dockerfile CMD指令中使用&& 如果要在Docker容器中运行多个服务,可能需要检查Supervisor。它使您能够在容器中运行多个守护进程。查看Docker文档,网址为
或者,您可以添加一个简单的bash脚本来启动两个守护进程,然后将CMD设置为使用您添加的bash文件。经过多次测试后,下面是一个Dockerfile,它可以在不使用MySQL的情况下安装OwnCloud:
# 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"]
然后
在您的浏览器中经过多次测试后,下面是一个Dockerfile,可以在不使用MySQL的情况下安装OwnCloud:
# 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"]
然后
在浏览器中,问题是CMD参数包含shell操作,但您使用的是CMD的exec形式,而不是shell形式。exec表单将参数传递给其中一个exec函数,该函数不会解释shell操作。shell表单将参数传递给sh-c 替换
CMD ["/etc/init.d/mysqld start && /etc/init.d/httpd start"]
与
或
请参阅。问题在于CMD参数包含shell操作,但您使用的是CMD的exec形式,而不是shell形式。exec表单将参数传递给其中一个exec函数,该函数不会解释shell操作。shell表单将参数传递给sh-c 替换
CMD ["/etc/init.d/mysqld start && /etc/init.d/httpd start"]
与
或
请参阅。谢谢您的回复。我试着只启动httpd来检查它是否可以在没有&&的情况下工作。但我也有同样的问题。我在一个有boot2docker的mac上,这可能是问题的一部分吗?那么,您在init.d中启动的脚本只会启动Apache进程,然后退出。如果我没有错,根据我在这里读到的:,RUN命令的-d参数作为deamon启动一个容器。我错了吗?所以我认为在我发送docker stop命令之前,使用-d运行映像将开始并且永远不会停止。谢谢您的回复。我试着只启动httpd来检查它是否可以在没有&&的情况下工作。但我也有同样的问题。我在一个有boot2docker的mac上,这可能是问题的一部分吗?那么,您在init.d中启动的脚本只会启动Apache进程,然后退出。如果我没有错,根据我在这里读到的:,RUN命令的-d参数作为deamon启动一个容器。我错了吗?因此,我认为在发送docker stop命令之前,使用-d运行映像将开始并且永远不会停止。
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"]