以下是构建SSHD、HTTPD、NGINX、TOMCAT、MYSQL、LNMP和REDIS的Dockerfile示例。请注意,为了简洁和清晰,这里只提供了每个服务的基础镜像构建示例。
SSHD:
FROM ubuntu:latest
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:yourpassword' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
HTTPD:
FROM centos:latest
RUN yum install -y httpd
RUN echo "Hello World" > /var/www/html/index.html
EXPOSE 80
CMD ["httpd", "-DFOREGROUND"]
NGINX:
FROM nginx:latest
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
TOMCAT:
FROM tomcat:latest
EXPOSE 8080
MYSQL:
FROM mysql:latest
ENV MYSQL_ROOT_PASSWORD yourpassword
EXPOSE 3306
LNMP (NGINX, MySQL, PHP):
FROM ubuntu:latest
RUN apt-get update && apt-get install -y nginx mysql-server php-fpm
RUN service mysql start
RUN echo "\n\
server {\n\
listen 80;\n\
root /var/www/html;\n\
index index.php index.html index.htm;\n\
location ~ \\.php$ {\n\
fastcgi_pass php-upstream;\n\
fastcgi_index index.php;\n\
include fastcgi_params;\n\
}\n\
}\n\
" > /etc/nginx/sites-available/default
RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf
RUN echo "\nphp-upstream" >> /etc/nginx/conf.d/default.conf
EXPOSE 80 3306
CMD service php-fpm start && service nginx start
REDIS:
FROM redis:latest
EXPOSE 6379
CMD ["redis-server"]
请注意,为了安全性,您应该更改所有示例中的密码(例如,yourpassword
),并且在生产环境中应该设置更复杂的配置和安全措施。