0

所以我有这个 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'

它建立起来了,没问题,MySQL 和 Apache 启动并正常工作,但 ssh 无法工作,我不知道为什么。openssh-server 已安装。

我试着像这样启动它:

#startup.sh file
#/bin/bash

sshd

+

ADD ./startup.sh /opt/startup.sh
ENTRYPOINT ["/opt/startup.sh"]

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

我究竟做错了什么?

4

2 回答 2

2

您正在前台启动 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 容器中运行多个进程:

于 2014-09-29T08:49:08.033 回答
0

替换 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 用于调试目的,这根本不是一个好习惯。

于 2014-09-29T17:16:42.307 回答