Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write Dockerfile script

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The knowledge points of this article include: writing Dockerfile scripts for tomcat, writing Dockerfile scripts for nginx.1.12.0, writing Dockerfile scripts for mysql, and deleting error images and container scripts. I believe you have some understanding of the writing of Dockerfile scripts after reading the complete article. Dockerfile script for tomcat

Cd / optmkdir tomcatcd tomcatvim DockerfileFROM centos:7MAINTAINER this is tomcat ADD jdk-8u91-linux-x64.tar.gz / usr/local/WORKDIR / usr/local/RUN mv jdk1.8.0_91 / usr/local/javaENV JAVA_HOME / usr/local/javaENV JAVA_BIN / usr/local/java/binENV JRE_HOME / usr/local/java/jreENV PATH $PATH:/usr/local/java/bin:/usr/local/java/jre/binENV CLASSPATH / usr/local/java/jre/bin:/usr/local/ Java/lib:/usr/local/java/jre/lib/charsets.jarADD apache-tomcat-8.5.16.tar.gz / usr/localWORKDIR / usr/local/RUN mv apache-tomcat-8.5.16 / usr/local/tomcat8EXPOSE 8080ENTRYPOINT ["/ usr/local/tomcat8/bin/catalina.sh" "run"] docker build-t tomcat:centos. Docker run-d-- name tomcat01-p 1216 run 8080-it tomcat:centosnginx.1.12.0 Dockerfile script cd / optmkdir nginxcd nginxvim Dockerfile FROM centos:7MAINTAINER this is nginx RUN yum-y updateRUN yum-y install wget pcre-devel zlib-devel make zlib gcc gcc-c++ openssl-devel net-toolsRUN useradd-M-s / sbin/nologin nginxADD nginx-1.12.0.tar.gz / usr/local/srcWORKDIR / usr/local/srcWORKDIR nginx-1.12. 0RUN. / configure\-- prefix=/usr/local/nginx\-- user=nginx\-- group=nginx\-- with-http_stub_status_module & make & & make installENV PATH / usr/local/nginx/sbin:$PATHEXPOSE 80EXPOSE 443RUN echo "daemon off "> / usr/local/nginx/conf/nginx.confWORKDIR / root/nginxADD run.sh / run.shRUN chmod 755 / run.shCMD [" / run.sh "] # nginx launch document vim run.shrun.shrunxdocker build-t nginx:new .docker run-d-P nginx:newmysql Dockerfile script mkdir mysqlcd mysql/vim DockerfileFROM centos:7MAINTAINER this is mysql RUN yum-y update# installs mysql according to the lazy environment package RUN yum-y install\ ncurses\ ncurses -devel\ bison\ cmake\ make\ gcc\ gcc-c++ # create and run user RUN useradd-s / sbin/nologin mysql# upload jingxADD mysql-boost-5.7.20.tar.gz / usr/local/src# compile and install WORKDIR / usr/local/src/mysql-5.7.20/RUN cmake\-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock\-DSYSCONFDIR=/etc\-DSYSTEMD_PID_DIR=/usr / local/mysql\-DDEFAULT_CHARSET=utf8\-DDEFAULT_COLLATION=utf8_general_ci\-DWITH_INNOBASE_STORAGE_ENGINE=1\-DWITH_ARCHIVE_STORAGE_ENGINE=1\-DWITH_BLACKHOLE_STORAGE_ENGINE=1\-DWITH_PERFSCHEMA_STORAGE_ENGINE=1\-DMYSQL_DATADIR=/usr/local/mysql/data\-DWITH_BOOST=boost\-DWITH_SYSTEMD=1 & & make & & make install# database directory to adjust permissions RUN chown-R mysql:mysql / usr/local/mysql/# adjust configuration file RUN rm -rf / etc/my.cnfADD my.cnf / etcRUN chown mysql:mysql / etc/my.cnf# set the environment variable ENV PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH# to initialize the database WORKDIR / usr/local/mysql/RUN bin/mysqld\-initialize-insecure\-user=mysql\-- basedir=/usr/local/mysql\-- datadir=/usr/local/mysql/dataRUN cp / usr/local/mysql/usr/lib/systemd/system/mysqld. Service / usr/lib/systemd/system/ADD run.sh / run.shRUN chmod 755 / run.shEXPOSE 3306CMD ["/ run.sh"] # CMD ["mysql_safe"] # my.cnf startup script vim my.cnf [root@localhost mysql-5.7.20] # vi / etc/ my.cnf [client] port = 3306default-character-set=utf8socket = / usr/local/mysql/ mysql.sockmysql] port = 3306default-character-set=utf8socket = / usr/local/mysql/ mysql.sock [mysqld] user = mysqlbasedir = / usr/local/mysqldatadir = / usr/local/mysql/dataport = 3306character_set_server=utf8pid-file = / usr/local/mysql/mysqld.pidsocket = / usr/local/mysql/mysql.sockserver-id = 1sql_mode=NO_ENGINE_SUBSTITUTION STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES#mysql permission script vim run.sh/usr/bin/systemctl start mysql.server & &\ mysql-e "grant all privileges on *. * to 'root'@'%' identified by' abc123' "& &\ mysql-e" grant all privileges on *. * to 'root'@'%' localhost identified by' abc123'; "docker build-t centos:mysql .docker run-- name=mysql_server-d-P-- privileged centos:mysql / usr/bin/initialize-insecuredocker exec-it image ID / bin/bash delete error image and container

Cd / opt

Vim none.shemaking binbinapachebashdocker ps-a | grep "Exited" | awk'{print $1}'| xargs docker stopdocker ps-a | grep "Exited" | awk'{print $1}'| xargs docker rmdocker images | grep none | awk'{print $3}'| xargs docker rmi

On the preparation of the Dockerfile script to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report