The creation of the simplest hello world output image is the easiest start, but if we need to modify our running code, or have input and output files, we have no way out. After each container is finished running, its allocated resources and file system will disappear, so we need to mount a volume to the docker container locally, so that when the container is running, file operations under the container's mount point will also affect the local volume mounted to the container. Just like mount in linux. In this way, we only need to modify the code in the local volume without modifying the image. For example, we create a Dockerfile: in: VOLUME: creates a mount point in the container. We can mount a local file volume under the container's /data, so that our operations in the container's data directory are the same as those on the local volume. CMD: The command to be run when the container is started. There can only be one. The operation of the created image is to count the information in a file and then input it into 2.txt. Use $docker build –t count:v1 ./ to create an image and view it When running, we need to add -v /root/laipeng.han/file:/data to mount the local file /root/laipeng.han/file under the container's /data, then all files under /root/laipeng.han/file can be seen under the container's /data/. The running command is: docker run -v /root/laipeng.han/file:/data count:v1 The final container outputs the result file 2.txt under /data/, which can also be seen under /root/laipeng.han/file/. In this way, we can modify the countfile.py code under /root/laipeng.han/file/ and run it directly without creating a new image file. The above codes have been tested personally, please feel free to run them. I hope they will be helpful for your study, and I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of the use of props in React's three major attributes
>>: CocosCreator implements skill cooling effect
I recently deployed and tested VMware Horizon, an...
From the backend to the front end, what a tragedy....
I finally finished the project at hand, and the m...
Command to add a route: 1.Route add route add -ne...
The <input> tag The <input> tag is us...
Docker Compose can realize the orchestration of D...
The specific code of the sliding button made with...
Table of contents Build a Docker image using Dock...
This article shares the specific code of Vue impo...
Table of contents 1. Background 2. Verification p...
This article example shares the specific code of ...
This article example shares the specific code of ...
The semantics, writing style, and best practices ...
CSS: Copy code The code is as follows: html,body{ ...
MySQL 8.0: MVCC for Large Objects in InnoDB In th...