cd /opt
mkdir nginx
cd nginx
vim Dockerfile
FROM centos //基于基础镜像为centos
MAINTAINER this is nginx image <377909726@qq.com> //描述信息
RUN yum install -y wget proc-devel net-tools gcc zlib zlib-devel make openssl-devel //安装环境包
RUN wget http://nginx.org/download/nginx-1.9.7.tar.gz //容器中下载Nginx软件包
RUN tar zxvf nginx-1.9.7.tar.gz //解压压缩包
WORKDIR nginx-1.9.7 //切换到文件目录中
RUN ./configure --prefix=/usr/local/nginx && make && make install //指定安装目录,执行安装
EXPOSE 80 //打开80端口
EXPOSE 443 //打开443端口
RUN echo "daemon off;">>/usr/local/nginx/conf/nginx.conf //关闭守护进程
ADD run.sh /run.sh //添加启动脚本
RUN chmod 755 /run.sh //为启动脚本增加执行权限
CMD ["/run.sh"] //启动容器时执行启动服务脚本
vim run.sh
#!/bin/bash
/usr/local/nginx/sbin/nginx //此处Nginx启动脚本位置为容器中位置
docker build -t nginx:new . //生成新镜像
docker run -d -P nginx:new //运行容器
docker ps -a //查看容器运行状态以及端口映射情况
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
535b90a8ec25 nginx:new "/run.sh" 11 seconds ago Up 10 seconds 0.0.0.0:32770->80/tcp, 0.0.0.0:32769->443/tcp practical_ride
docker rmi none镜像ID --force
docker images //发现none镜像已经删除
docker rm 容器ID //删除多余无用的容
编写脚本删除,然后执行脚本即可:
vim none.sh
docker ps -a | grep "Exited" | awk ‘{print $1 }‘|xargs docker stop
docker ps -a | grep "Exited" | awk ‘{print $1 }‘|xargs docker rm
docker images|grep none|awk ‘{print $3 }‘|xargs docker rmi
source none.sh
tar zxvf nginx-1.12.0.tar.gz -C /opt/nginx/
ls
vim Dockerfile
FROM centos
MAINTAINER this is Nginx image<37790972@qq.com>
RUN yum install -y wget proc-devel net-tools gcc zlib zlib-devel make openssl-devel
ADD nginx-1.12.0 /nginx-1.12.0 //与上面不同的地方,直接将解压好的软件包复制到容器中根目录下
# RUN tar zxvf nginx-1.9.7.tar.gz
WORKDIR /nginx-1.12.0
RUN ./configure --prefix=/usr/local/nginx && make && make install
EXPOSE 80
EXPOSE 443
RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf
ADD run.sh /run.sh
RUN chmod +x /run.sh //增加执行权限
CMD ["/run.sh"]
docker build -t nginx:new .
docker images
docker run -d -P nginx:new
docker ps -a
mkdir -p /opt/tomcat
tar zxvf jdk-8u91-linux-x64.tar.gz
tar zxvf apache-tomcat-8.5.16.tar.gz
vim Dockerfile
FROM centos
MAINTAINER this is tomcat image <377909726@qq.com>
ADD jdk1.8.0_91 /usr/local/java
ENV JAVA_HOME /usr/local/java
ENV JAVA_BIN /usr/local/java/bin
ENV JRE_HOME /usr/local/java/jre
ENV PATH $PATH:/usr/local/java/bin:/usr/local/java/jre/bin
ENV CLASSPATH /usr/local/java/jre/bin:/usr/local/java/lib:/usr/local/java/jre/lib/charsets.jar
ADD apache-tomcat-8.5.16 /usr/local/tomcat8
EXPOSE 8080
docker build -t tomcat:centos .
docker run --name tomcat01 -p 80:8080 -it tomcat:centos /bin/bash
[root@87ba5cead994 bin]#cd /usr/local/tomcat8/bin
[root@87ba5cead994 bin]#./startup.sh //启动tomcat服务
mkdir -p /opt/mysql
cd mysql
vim Dockerfile
FROM guyton/centos6
MAINTAINER this is msyql images <377909726@qq.com>
RUN yum install mysql mysql-server
RUN /etc/init.d/mysqld start &&mysql -e "grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘abc123‘;" &&mysql -e "grant all privileges on *.* to ‘root‘@‘localhost‘ identified by ‘abc123‘;"
EXPOSE 3306
CMD ["mysqld_safe"]
docker build -t centos6:mysql .
docker run --name=mysqlserver -d -P centos6:mysql
docker ps -a
mysql -h 192.168.144.111 -u root -P 32768 -pabc123
原文:http://blog.51cto.com/13659253/2160377