cd /opt
mkdir nginx
cd nginx
vim Dockerfilejava
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.shmysql
#!/bin/bash /usr/local/nginx/sbin/nginx //此處Nginx啓動腳本位置爲容器中位置
docker build -t nginx:new . //生成新鏡像
docker run -d -P nginx:new //運行容器
docker ps -a //查看容器運行狀態以及端口映射狀況linux
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 //刪除多餘無用的容nginx
編寫腳本刪除,而後執行腳本便可:sql
vim none.shdocker
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.shapache
tar zxvf nginx-1.12.0.tar.gz -C /opt/nginx/
lsvim
vim Dockerfilecentos
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 -atomcat
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