一、java相关
0.基于镜像安装java
FROM openjdk:8-jdk-alpine (openjdk:8)
COPY ./docker-demo.jar /tmp/app.jar
EXPOSE 80
ENTRYPOINT java -jar /tmp/app.jar
1.手动安装jdk和tomcat
FROM centos:7
ADD jdk-8u333-linux-x64.tar.gz /usr/local
ADD apache-tomcat-9.0.64.tar.gz /usr/local
COPY index.jsp /usr/local/apache-tomcat-9.0.64/webapps/
RUN yum -y install vim
WORKDIR /usr/local
ENV JAVA_HOME=/usr/local/jdk1.8.0_333
ENV CATALINA_HOME=/usr/local/apache-tomcat-9.0.64
ENV CATALINA_BASH=/usr/local/apache-tomcat-9.0.64
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
EXPOSE 8080
CMD /usr/local/apache-tomcat-9.0.64/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.64/logs/catalina.out
2.基于tomcat镜像安装
From hub.c.163.com/library/tomcat:latest
MAINTAINER liping haha@123.com
COPY jpress.war /usr/local/tomcat/webapps
二、python相关
3.基于python镜像安装 (pip freeze > requirements.txt)
From python:3.7
COPY ./app.py /tmp/app.py
COPY ./requirements.txt /tmp/requirements.txt
WORKDIR /tmp
RUN pip install -r requirements.txt
EXPOSE 8080
CMD ["python","app.py"]
4.不需要安装框架的python
FROM python:3.7
COPY ./youxi.py /tmp/
WORKDIR /tmp
EXPOSE 8080
CMD ["python","youxi.py"]
三、php相关
1).dockerfile
FROM centos:7
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
&& curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo \
&& yum clean all \
&& yum clean all && yum makecache \
&& yum install -y php php-fpm php-mysql mysql \
&& yum install -y nginx
ADD wordpress.tar.gz /usr/share/nginx/
RUN mv /usr/share/ngin x/wordpress/* /usr/share/nginx/html
RUN chmod 777 -R /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
ENV DBPASS=123456
EXPOSE 80 443 3306
COPY run.sh /
CMD ["bash","/run.sh"]
2)tar.gz nginx.conf run.sh
! /usr/bin/bash
php-fpm
nginx
tail -f /var/log/nginx/access.log
3)mysql 容器部署
docker pull mariadb:latest
docker run -itd -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=wordpress --name mysql mariadb:latest
-e声明环境变量,定义密码为123456,同时create一个wordpress的库
4)创建镜像
docker build -t wordpress:v1 . # . 不能省略哦
如果使用绝对路径的话应该是 docker build -f /opt/xxx/Dockerfile . -t wordpress:v1
docker run -itd --link mysql -p 80:80 --name wordpress --privileged=true wordpress:v1/usr/sbin/init (...--privileged=true ../usr/sbin/init 特权模式)