简体   繁体   English

Docker ERROR:从Win10运行时找不到容器命令或不存在容器命令

[英]Docker ERROR: Container command not found or does not exist when running from Win10

This is driving me crazy... 这真让我抓狂...

I have Win10 and I have installed the Docker Toolbox with 我有Win10,我已经安装了Docker Toolbox

Docker=1.10.2 
Compose=1.6.0 
VirtualBox=5.0.14

I have successfully launched the LAMP in Linux [Amazon linux] but when I try to do the same the terminal responds with "ERROR: Container command not found or does not exist" As I understand, there is something wrong with the way Windows interpreter the CMD syntax. 我已经在Linux [亚马逊linux]中成功启动了LAMP但是当我尝试做同样的事情时,终端响应“错误:容器命令未找到或不存在”据我所知,Windows解释器的方式有问题CMD语法。

I have tried 我试过了

 - CMD ["/run.sh"]
 - ENTRYPOINT ["/run.sh"]     
 - CMD /run.sh
 - CMD '/run.sh'
 - CMD run.sh
 - CMD "/run.sh"

but nothing seems to work. 但似乎没什么用。

Note: When I run CMD /run.sh the error does not appear but the container exits immediately. 注意:当我运行CMD /run.sh时,错误不会出现,但容器会立即退出。

Note2: I have exactly the same problem when trying to setup the LAMP with Docker-Machine on AWS 注2:尝试在AWS上使用Docker-Machine设置LAMP时,我遇到了完全相同的问题

I have this DockerfileLamp : 我有这个DockerfileLamp

FROM ubuntu

# -- Install needed packages --
ENV DEBIAN_FRONTEND noninteractive

# -- Install additional utilities --
RUN apt-get update && \
  apt-get install -y supervisor git curl apache2 mcrypt cron wget nano unzip

# -- Install PHP 5.5 --
RUN apt-get -y update && \
    apt-get -y install php5 libapache2-mod-php5 mysql-server-5.5 php5-mysql pwgen php-apc php5-mcrypt php5-xdebug php5-gd php5-curl php-pear openssh-server php5-cli php5-apcu php5-intl php5-imagick php5-json

# -- Set localhost to apache conf file --
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf

# -- Add image configuration and scripts --
ADD ./lamp/start-apache2.sh /start-apache2.sh
ADD ./lamp/start-mysqld.sh /start-mysqld.sh
ADD ./lamp/run.sh /run.sh
RUN chmod 755 /*.sh
ADD ./lamp/my.cnf /etc/mysql/conf.d/my.cnf
ADD ./lamp/supervisord-apache2.conf 
    /etc/supervisor/conf.d/supervisord-apache2.conf
ADD ./lamp/supervisord-mysqld.conf 
    /etc/supervisor/conf.d/supervisord-mysqld.conf

# -- Remove pre-installed database --
RUN rm -rf /var/lib/mysql/*
# -- Add MySQL utils --
ADD ./lamp/setup_MySQL.sh /setup_MySQL.sh
RUN chmod 755 /*.sh

# -- config to enable .htaccess --
##ADD apache_default /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite

# -- Environmental variables to configure php --
ENV PHP_UPLOAD_MAX_FILESIZE 10M
ENV PHP_POST_MAX_SIZE 10M

# -- Add volumes for MySQL --
##VOLUME  ["/etc/mysql", "/var/lib/mysql" ]

# -- Set up SSH server --
RUN mkdir /var/run/sshd
RUN echo 'root:root' |chpasswd
RUN sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/'
    /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
ADD ./lamp/supervisord-openssh-server.conf
    /etc/supervisor/conf.d/supervisord-openssh-server.conf

# -- Install Python & pip --
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y python python-pip python-dev && \
    pip install --upgrade pip
# -- Install xvfb --
RUN apt-get install -y xvfb   

EXPOSE 80 3306 22

CMD /run.sh

and the run.sh : run.sh

#!/bin/bash

VOLUME_HOME="/var/lib/mysql"

sed -ri -e "s/^upload_max_filesize.*/upload_max_filesize = ${PHP_UPLOAD_MAX_FILESIZE}/" \
    -e "s/^post_max_size.*/post_max_size = ${PHP_POST_MAX_SIZE}/" /etc/php5/apache2/php.ini
if [[ ! -d $VOLUME_HOME/mysql ]]; then
    echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME"
    echo "=> Installing MySQL ..."
    mysql_install_db > /dev/null 2>&1
    echo "=> Done!"  
    /setup_MySQL.sh
else
    echo "=> Using an existing volume of MySQL"
fi

exec supervisord -n

and the docker-compose.yml : docker-compose.yml

lamp: # apache + mysql/php
  build: .
  dockerfile: DockerfileLamp
  ports:
    - "8181:80"   # open apache to public
    - "3333:3306" # open mysql to public 
    - "2222:22"   # open SSH to public

Docker is process centric, in other words your containers dies when your CMD script dies. Docker是以流程为中心的,换句话说,当您的CMD脚本死亡时,您的容器会死亡。 At the end of your script run ... 在脚本运行结束时......

tail -f logfile (where logfile is some logfile you are interested in)

This will 这将

1 - stop your container exiting 2 - allow you to do 1 - 停止您的容器退出2 - 允许您这样做

docker logs -f containerName

To help u debug 帮助你调试

3 - allow you to enter into the container with 3 - 允许你进入容器

docker exec -it bash containerName 

Then u can run the command that you think is failing inside the container and try n sort this out 然后你可以运行你认为在容器内失败的命令并尝试将其排序

Whilst this doesn't directly answer your question it should give u sufficient weaponry to attack this issue 虽然这不能直接回答你的问题,但它应该给你足够的武器来攻击这个问题

For another project I tried to get to work on Windows with Docker Machine I ran into the same ambiguous error message of docker-compose Container command not found or does not exist . 对于另一个我尝试使用Docker Machine在Windows上工作的项目,我遇到了相同的模糊错误消息:docker-compose Container command not found or does not exist

Your comment about line endings triggered me to try dos2unix ./*/*.sh within git-bash (multiple scripts, in subfolders), which fixed the issue for me. 你对行结尾的评论引发我在git-bash (多个脚本,子文件夹)中尝试dos2unix ./*/*.sh ,这为我解决了这个问题。

My suspicion is that git clone saves the files with DOS line endings, which results in incorrect syntax for the top line !#/bin/bash . 我怀疑是git clone用DOS行结尾保存文件,导致顶行的语法不正确!#/bin/bash

$ docker-compose -v
docker-compose version 1.6.2, build e80fc83

$ docker version
Client:
 Version:      1.10.3
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   20f81dd
 Built:        Thu Mar 10 21:49:11 2016
 OS/Arch:      windows/amd64

Server:
 Version:      1.10.3
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   20f81dd
 Built:        Thu Mar 10 21:49:11 2016
 OS/Arch:      linux/amd64

I solved it by simplifying the file. 我通过简化文件解决了这个问题。 I commented out all the controls because whatever I tried it would keep throwing Syntax Errors 我注释掉了所有控件,因为无论我尝试什么,它都会不断抛出Syntax Errors

#!/bin/bash

VOLUME_HOME="/var/lib/mysql"

sed -ri -e "s/^upload_max_filesize.*/upload_max_filesize = ${PHP_UPLOAD_MAX_FILESIZE}/" \
    -e "s/^post_max_size.*/post_max_size = ${PHP_POST_MAX_SIZE}/" /etc/php5/apache2/php.ini

#if [[ ! -d $VOLUME_HOME/mysql ]]; then
    echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME"
    echo "=> Installing MySQL ..."
    mysql_install_db > /dev/null 2>&1
    echo "=> Done!"
    /setup_MySQL.sh
#else
#    echo "=> Using an existing volume of MySQL"
#fi

exec supervisord -n

It works for my case so I am not going to investigate further. 它适用于我的情况,所以我不打算进一步调查。 Cheers! 干杯!

EDITED EDITED

The above solution was not so complete. 上述解决方案并不完整。 It worked because I was making changes from INSIDE the container. 它起作用,因为我正在从INSIDE容器中进行更改。

The permanent solution goes like this : I migrated the run.sh file to a private Gist . 永久解决方案如下:我将run.sh文件迁移到私有Gist。 [It does not need to be private but ok] I think the problem is that when I try to build the Dockerfile from Windows machine [either locally or on a cloud provider] it messes up the syntax , EOF , line breaks and whatnot. [它不需要是私有的但是确定]我认为问题是当我尝试从Windows机器[本地或云提供商]构建Dockerfile时,它会弄乱语法,EOF,换行符等等。 So I broke out of it by ADDing the gist url 所以我通过添加要点网址来打破它

ADD http://gist_url/run.sh /run.sh

Note1: You must use the raw file URL otherwise you are going to get the complete HTML. 注意1:您必须使用原始文件URL,否则您将获得完整的HTML。

Note2: The private gist is not protected.You don't need authentication to fetch the URL. 注意2:私有要点不受保护。您不需要身份验证来获取URL。

暂无
暂无

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

相关问题 在 Windows KVM 实例中运行 Win10 Docker 容器时出错 - Error running Win10 Docker container in Windows KVM instance Docker:在从 Win10 安装到运行 ubuntu 的容器的目录中不允许进行 git 操作 - Docker: git operations not permitted in dir which is mounted from Win10's to container running ubuntu 运行cabal时在win10上出现“无效参数”错误 - “invalid argument” error on win10 when running cabal Vagrant 2.2 on Win10错误在提供程序“ docker”上 - Vagrant 2.2 on Win10 Error on Provider “docker” Win10上的sysprep退出时出现错误RunExternalDlls:未运行DLL - sysprep on Win10 exits with error RunExternalDlls:Not running DLLs Windows上的docker-compose - 找不到容器命令'sh'或不存在 - docker-compose on Windows - Container command 'sh' not found or does not exist Powershell:在此 object (WIN10 - 18363) 上找不到属性“WorkingDirectory”,但存在 - Powershell: The property 'WorkingDirectory' cannot be found on this object (WIN10 - 18363) but exist 将路径中有空格和破折号的 Win10 目录挂载到 Ubuntu Docker 容器中 - Mounting Win10 directory that has spaces and dashes in the path into Ubuntu Docker Container 来自守护程序的错误响应:从 openzim/zim-tools 的 Docker 映像运行命令时容器未运行 - Error response from daemon: Container is not running when running command from Docker image of openzim/zim-tools 运行Win10 Insider的Windows Docker Swarm IIS服务但无法访问 - Docker for Windows Swarm IIS Service with Win10 Insider running but unreachable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM