Docker_dockerfile nginx and tomcat

1, Classification of images 1. Three elements of docker 1) , Docker Image is a read-only template. An Image can be used ...

1, Classification of images
1. Three elements of docker
1) , Docker Image is a read-only template. An Image can be used to create Docker containers. One Image can create many containers.
2) , Container
1.Docker uses a Container to run one or a group of applications independently
2. The container uses the running instance created by the image
3. Containers can be started, started, stopped and deleted. Each container is isolated from each other to ensure the safety of the platform.
4. The container can be regarded as a simple Linux environment (including root user permission, process space, user space and network space) and applications running in it.
5. The definition of container is almost the same as that of image. It is also a unified perspective of a pile of layers. The only difference is that the top layer of container is readable and writable.
3) , Repository
1. A Repository is a place for centralized storage of image files.
2. There is a difference between a Repository and a warehouse registration server. The warehouse registration server often stores multiple warehouses. Each warehouse contains multiple images, and each image has a different tag.
3. The warehouse is divided into Public warehouse and Private warehouse.
4. The largest open warehouse is Docker Hub( https://hub.docker.com/ ), a large number of images are stored for users to download.
5. Domestic public warehouses include Alibaba cloud, Netease cloud, etc.
2, dockerfile layering principle
base image
The base image has two meanings: it does not depend on other images, and can be expanded by building other images from scratch. Therefore, the base image is generally the Docker image of various Linux distributions, such as Ubuntu, Debian or CentOS.
The base image provides the minimum installed Linux distribution.

3, Build Nginx
1. Build image

[root@docker ~]# mkdir nginx [root@docker ~]# vim nginx/Dockerfile
#Basic image (centos needs lowercase) FROM centos:7 #User information MAINTAINER THIS IS NGINX IMAGE Add environment package RUN yum -y update RUN yum install -y pcre-devel zlib-devel gcc gcc-c++ make RUN useradd -M -s /sbin/nologin nginx #Unzip nginx package ADD nginx-1.12.2.tar.gz /usr/local/src #Specify the working directory (equivalent to cd) WORKDIR /usr/local/src WORkDIR nginx-1.12.2 RUN ./configure \ --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx \ --with-http_stub_status_module && make && make install ENV PATH /usr/local/nginx/sbin:$PATH #Specify the httpd port EXPOSE 80 RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf CMD nginx

2. Upload nginx package

[root@docker ~]# cd nginx [root@docker nginx]# ls Dockerfile [root@docker nginx]# rz -E [root@docker nginx]# ls Dockerfile nginx-1.12.2.tar.gz

3. Build image

docker build -f Dockerfile -t nginx:new . docker run -d -P nginx:new #Run mirror
[root@docker nginx]# docker run -d -P nginx:new f18a5ddda8c0331a341e6fc4ccef615e2119c93acd98868766b52c7df649594a [root@docker nginx]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f18a5ddda8c0 nginx:new "/bin/sh -c nginx" 32 seconds ago Up 32 seconds 0.0.0.0:49153->80/tcp, :::49153->80/tcp sweet_aryabhata a3a1d2b372b8 hello-world "/hello" 29 minutes ago Exited (0) 29 minutes ago priceless_colden


4, Tomcat construction
1. Build image

FROM centos:7 MAINTAINER build image tomcat <tang> EXPOSE 8080 ADD jdk-8u91-linux-x64.tar.gz /usr/local/src WORKDIR /usr/local/src ENV JAVA_HOME /usr/local/src/jdk1.8.0_91 ENV CLASSPATH $JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar ENV PATH $JAVA_HOME/bin:$PATH ADD apache-tomcat-9.0.16.tar.gz /usr/local/src RUN mv apache-tomcat-9.0.16/ /usr/local/tomcat9 &> /dev/null ENV PATH /usr/local/tomcat9/bin/:$PATH ADD tomcat9.run.sh /usr/local/src RUN chmod 755 /usr/local/src/tomcat9.run.sh &> /dev/null CMD ["/usr/local/src/tomcat9.run.sh"] vim tomcat9.run.sh #!/bin/bash /usr/local/tomcat9/bin/catalina.sh run

2. Generate image

[root@docker Tomcat]# docker build -t tomcat:test . [root@docker Tomcat]# docker images |grep tomcat tomcat test b6fcee8f8fb0 About a minute ago 599MB

3. Create containers

[root@docker Tomcat]# docker run -d -P tomcat:test 49b92eee4f800bfc2611254d2996a404afae52e04f570c5fcc52261cfed27e06 [root@docker Tomcat]# docker ps -a |grep tomcat 49b92eee4f80 tomcat:test "/usr/local/src/tomc..." 12 seconds ago Up 11 seconds 0.0.0.0:49154->8080/tcp, :::49154->8080/tcp blissful_saha


5, Tomcat image optimization based on dockerfile
1. Create a directory and write a Dockerfile file

vim Dockerfile FROM frolvlad/alpine-oraclejdk8 ADD apache-tomcat-9.0.16.tar.gz /usr/local/ WORKDIR /usr/local/ RUN mv /usr/local/apache-tomcat-9.0.16 /usr/local/tomcat &>/dev/null RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && sed -i "s#securerandom.source=file:/dev/random#securerandom.source=file:/dev/urandom#g" $JAVA_HOME/jre/lib/security/java.security EXPOSE 8080 ENTRYPOINT ["/usr/local/tomcat/bin/catalina.sh","run"]

2. Generate image

[root@docker Tomcat]# docker build -t tomcat:new . [root@docker Tomcat]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat new ca84190d524b 44 seconds ago 199MB tomcat test b6fcee8f8fb0 19 minutes ago 599MB nginx new 2aefb78c6db3 46 minutes ago 681MB hello-world latest d1165f221234 6 months ago 13.3kB centos 7 8652b9f0cb4c 10 months ago 204MB frolvlad/alpine-oraclejdk8 latest 7f2049911fa1 2 years ago 169MB

3. Create container

[root@docker Tomcat]# docker run -d -P tomcat:new fced2d2e61cd9b486da249ce073beafbe313ee3ee527a9405fef8753c953a345 [root@docker Tomcat]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fced2d2e61cd tomcat:new "/usr/local/tomcat/b..." 13 seconds ago Up 11 seconds 0.0.0.0:49155->8080/tcp, :::49155->8080/tcp happy_proskuriakova 49b92eee4f80 tomcat:test "/usr/local/src/tomc..." 18 minutes ago Up 18 minutes 0.0.0.0:49154->8080/tcp, :::49154->8080/tcp blissful_saha f18a5ddda8c0 nginx:new "/bin/sh -c nginx" 53 minutes ago Up 53 minutes 0.0.0.0:49153->80/tcp, :::49153->80/tcp sweet_aryabhata a3a1d2b372b8 hello-world "/hello" About an hour ago Exited (0) About an hour ago priceless_colden

11 September 2021, 19:58 | Views: 1164

Add new comment

For adding a comment, please log in
or create account

0 comments