Some precautions need to use docker

1, the program needs the foreground

      Program must be executed in the foreground, if it is, then do not have java process nohup way or use the service running in the background

      Otherwise, problems may occur frequently started applications

      The reason is that a process mirrored docker only manage running (there is no special need to do a mirrored two phenomena occur after the execution, to make use of pod k8s to solve)

2, the front desk to print the log

      Direct console log output to the front desk, docker automatically collect log stdout output. Do not fight the presence of two log settings, such as a file, a console and so on.

3, is preferably placed in the configuration file or image can be read remotely, optionally not be read volume mount directory

      Some programs are external configuration file, run the package and configuration files are not executed in a single package.

      If there is the above profile can be run and the mirror which are included in the package.

      If you need to make some configuration files modified or replaced in a different environment, we need to fight each application program mirroring or modified look, it just remote access configuration file. Mirror were playing not in line with the entire publishing process, because each playing middle mirror package may vary, resulting in different production and development testing.

      Another way is to use configmap service k8s to solve the problem of the corresponding read the file.

4, using the data volume

      After each run whether you have specified container does not show the data volume is created, there will exist a temporary volume to store some temporary files generated

      These temporary files with the life cycle of container changes

      If you specify directly created the data volume must be created in the shared storage inside

      Otherwise the situation can not read data after container will drift

      This service is called "stateful" service, in general our services to achieve the "non-state"

      If your service is stateful, it can make use of k8s the Statue FUL the SET to achieve, including the startup sequence number to the service and other operations.

5, network-related precautions (do not have to create a network-related operations)

      (We almost less than)

      Let docker within the service to identify the correct card

6、dockerfile

      Here I define a micro-service springboot corresponding dockerfile image package file to play, no matter what way you are now finally are essentially mirrored using dockerfile to play

      (If our process is not a person on the line is completed, it is not recommended to use the form maven plugin be playing mirror package, because the operation and maintenance personnel are likely to understand or test your file maven pom can not modify your configuration, this might give post-maintenance is the only known cause trouble .dockerfile generated image file based, you can use the upgrade version control management, etc. with your application. mirroring is a black box that can be used in the docker file system, but he is not an independent file.)

   
FROM com.cn/java:8-jdk-alpine-asla-shanghai-1-skyagent-3
VOLUME /tmp
ADD springcloud-zjs-example-mysql-0.0.1.jar app.jar
EXPOSE 11005
ENV JAVA_OPTS="" AGENT_SERVICE_NAME="default" AGENT_COLLECTOR_ADDRESS="10.10.6.79:11800"
ENTRYPOINT java -javaagent:/usr/local/skyagent/skywalking-agent.jar=agent.service_name=${AGENT_SERVICE_NAME},collector.backend_service=${AGENT_COLLECTOR_ADDRESS} ${JAVA_OPTS} -jar /app.jar

 

       The following link is an explanation of the above documents

     https://github.com/zygfengyuwuzu/docker-miscellaneous

       The three parameters set dockerfile

              JAVA_OPTS parameter is the jdk, this parameter can be set to optimize memory and other related jvm own

              AGENT_SERVICE_NAME is to set the name of skywalking

              AGENT_COLLECTOR_ADDRESS address setting data transmission skywalking

             All configuration items SpringBoot project are adjustable parameters, without special designated.

        If you do not need to be monitored skywalking last sentence can be modified under way, leaving only the parameters jdk

        ENTRYPOINT java ${JAVA_OPTS} -jar /app.jar

7, playing mirroring some of the problems

      When packing the packages dockerfile jar and preferably in the same path

      This is easier to specify the mirror into the path of the file

      Not easy to make mistakes and do not need to file by mistake into the mirror possible

      (May be required into the image files are placed in a folder or directory in the same directory and dockerfile)

       Play is best to use a server image package to package and upload, because many times there will be generated locally mirrored cache files very quickly

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

       For how to achieve integrated automation can refer to the following blog (this blog is jenkins integrated with docker swarm example, swarm can be replaced k8s, corresponding plug a change)

    https://www.cnblogs.com/zhyg/p/7845612.html

 

Guess you like

Origin www.cnblogs.com/zhyg/p/11239043.html