Micro Services Architecture ------ Dockerfile customized image

Docker containers not only run native container, but to our specific project can be placed on top of the container to go, that's what Docker customized image needs to be done. = New Docker Docker containers after mirror image equivalent to the class, the object corresponding to the container, so that the modified classes, the container is produced in accordance with the generated demand.

According Dockerfile below to create a simple custom mirror: Start tomcat container home page displays hello tomcat 

1.Dockerfile customized image

  • First, find a place to put our project code, our general program will be placed under / usr / local /
  • cd /usr/local/      mkdir docker    cd docker    mkdir  myproject   cd myproject
  • touch index.jsp    vi index.jsp    hello tomcat  保存
  • touch Dockerfile # Dockerfile create files, configuration files are generally mirrored to build customized default name is Dockerfile, following is the content of the document

    From tomcat:latest 

    COPY index.jsp  /usr/local/tomcat/webapps/ROOT

  • From tomcat: latest # inherited from the mirror tomcat, tomcat is the latest version, the same can also be used to replace the version number of tomcat latest Copy index.jsp / usr / local / tomcat / webapps / ROOT # copy the file to the tomcat index.jsp ROOT save directory
  • docker build -t image name. Construction of the mirror look, there is a final point. Meaning that the last point is the context of the current directory and container. Construction of the mirror is not the host inside the building but built in Docker, the process of building a copy of the current directory where all files and directories to Docker, so use the ./ in Dockerfile want to jump back to a higher level directory does not work, because the environment has changed after the construction.
  • Docker images using a mirror to view information about the current docker, myshop is a mirror image I created, mirroring the size of tomcat same, because the mirror itself is based on the creation of a tomcat.

  

  • docker run -p 8080: 8080 --name myshop -d myshop myshop mirrored building myshop container port mapped to the external network 8080 and run as a daemon thread name --name container -d myshop in order to protect the thread running myshop Mirror
  • docker ps view the current running docker container docker container rm container id delete container docker container ls -a shows all the run-off container, the container can not run the name of the same name history container. You can delete the recorded history of the container, and then run

  

  • operation result

  

 

 

 2.Dockerfile instruction

  • COPY Copy the file to a directory format: COPY filename target path or file name with path
  • ADD and COPY commands essentially similar, but has added some features to add functionality to the same command format: After the copy is complete, if the compressed file is automatically executed when the target file parsing file directory
  • CMD execute script commands CMD ./startup.sh only allowed once more CMD will perform the last
  • ENTRYPOINT also execute a script command CMD essentially similar, is only allowed to use multiple commands one can start to write a set of scripts, all commands are added to it, and then start ENTRYPOINT
  • ENV environment variable k = v
  • EXPOSE port exposed,
  • WORKDIR similar to cd into the directory specified container initial directory

3. interact with the docker container

  docker exec -it vessel name / bin / bash shell scripts to interact  

 

 

 

Guess you like

Origin www.cnblogs.com/zmeRecord/p/11806442.html