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
This article uses an example to describe how to c...
This article shares the mysql5.6.24 automatic ins...
This article shares the specific code for JavaScr...
Table of contents 1. Introduction to Harbor 1. Ha...
This is my first blog post. Due to time constrain...
Table of contents Preface Discover the cause Cust...
<textarea></textarea> is used to crea...
Table of contents Official introduction to Node.j...
In the previous article, I introduced the functio...
1. Overview Redis Cluster enables high availabili...
Preface In daily code development, there are many...
Table of contents ESLint plugin installation in H...
Table of contents 1. Use help information 2. Crea...
This article uses examples to illustrate the func...
Preface A character set is a set of symbols and e...