2014-10-09 229 views
1

我是新來的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.

回答

0

多次測試後,這裏是工程安裝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 

在瀏覽器

1

我想這是因爲你想在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

0

的問題是,你的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

相關問題