Mysql 为什么到docker容器的SSH连接不起作用?

Mysql 为什么到docker容器的SSH连接不起作用?,mysql,apache,ssh,docker,sshd,Mysql,Apache,Ssh,Docker,Sshd,所以我有一个Dockerfile: FROM debian:squeeze MAINTAINER Name < email : > # Update the repository sources list RUN apt-get update # Install apache, PHP, and supplimentary programs. curl and lynx-cur are for debugging the container. RUN DEBIAN_FRONT

所以我有一个Dockerfile:

FROM debian:squeeze

MAINTAINER Name < email : >

# Update the repository sources list

RUN apt-get update

# Install apache, PHP, and supplimentary programs. curl and lynx-cur are for debugging the container.
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 build-essential php5 mysql-server openssh-server libapache2-mod-php5 php5-mysql php5-gd php-pear php-apc php5-curl curl lynx-cur

# Enable apache mods.
RUN a2enmod php5
RUN a2enmod rewrite

# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

EXPOSE 80

# Copy site into place.
ADD www /var/www/site

# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf

# start mysqld and apache

EXPOSE 3306

RUN mkdir /var/run/sshd
RUN echo 'root:123' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config

EXPOSE 22

CMD bash -c ' (mysqld &); /usr/sbin/apache2ctl -D FOREGROUND;/usr/sbin/sshd -D'
+

还有很多其他的,我被卡住了


我做错了什么?

您正在前台启动apache,因此apachectl进程将永远不会向启动它的shell发回手,因此永远不会调用/usr/sbin/sshd-D(除非您杀死apache)

以下指令将在后台启动mysql和apache,然后在前台启动sshd:

CMD bash -c ' (mysqld &); /usr/sbin/apache2ctl start;/usr/sbin/sshd -D'
虽然这样的
CMD
语句对于测试来说是可以的,但我建议使用不同的方法在单个docker容器中运行多个进程:


替换docker文件中的以下代码行

RUN mkdir /var/run/sshd
RUN echo 'root:123' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
使用这些代码

RUN apt-get install -y openssh-server
RUN echo 'root:password' |chpasswd
RUN mkdir -p /var/run/sshd
这对我有用

注意:仅出于调试目的使用ssh,这根本不是一个好的做法。

docker logs'是怎么说的?
RUN mkdir /var/run/sshd
RUN echo 'root:123' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN apt-get install -y openssh-server
RUN echo 'root:password' |chpasswd
RUN mkdir -p /var/run/sshd