This article is a mirror article of machine translation, please click here to jump to the original article.

View: 6464|Reply: 0

[Practical combat] Create a Docker image based on Nginx

[Copy link]
Posted on 11/8/2019 10:50:21 AM | | | |
A Dockerfile is a text document containing commands for combining images. Any command can be invoked in the command line. Docker automatically generates images by reading instructions in the Dockerfile.

There are many ways to create an image, either by taking an existing image from Docker Hub and updating it, or by leveraging the local file system.

1. Pull the nginx image



2. Run the nginx container

Create an nginx image named nginx_test and map port 8800 to container port 80

Once inside the container,Start the nginx service, the command is as follows:

In the past, when the nginx container was successfully launched, the services inside would also start, but now I don't know what's going on.

Create a new test.txt file with the following contents: itsvse.com

Access http://ip:8800/test.txt as shown below:



Look at the running docker container, docker ps, as shown in the image below:



3. Check for changes to the file structure in the container

It contains the test.txt files we created, and the other files are files generated or modified by starting the nginx service, as shown in the figure below:



4. Build a mirror

Create a new image from the container with the following command:

-a: Submitted mirror author;
-c: Use the Dockerfile command to create an image;
-m: Caption text at the time of submission;
-p: On commit, pause the container.


[root@dev-itsvse opt]# docker commit -a "by:itsvse.com" -m "nginx test" 3130505af61e  mynginx:v1
sha256:a8fb3076b5bd1ad8f6e7085bd452318e6195dad22411c62913424ae26b5dfff8
[root@dev-itsvse opt]# docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
mynginx                                v1                  a8fb3076b5bd        11 seconds ago      126MB



5. Save the image
docker save: Save the specified image as a tar archive.



##-o: Specifies the name of the saved image; mynginx_test.tar: The name of the image saved to your local location; mynginx: The name of the image, viewed through "docker images"



Send the image to someone else, and then import the tar package to the local docker image.

6. Run the created image



Run the nginx service


Access: http://ip:8801/test.txt









Previous:Decoding the Complete Collection of Blockchain
Next:Use GPU-accelerated ffmpeg to process tasks under Windows
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com