Create a Custom Image
<p>This article uses the creation of a Linux custom image on the Windows platform as an example.</p>
<p><strong>Procedures</strong></p>
<p>1. Make a json file that meets your requirements according to the various fields introduced above.</p>
<p>2. Execute the command packer build xxx.json to create a custom image.</p>
<p>3. The sample operation results are as follows, the following example will create a custom image with Redis.</p>
<pre>
<code>PS C:\ > .\packer.exe build "C:\HKA_LINUX.json"
pacloud output will be in this color.
==> pacloud: zone_name:[HKA] url:[https://api.yun.pingan.com/api/v1] timeout:[10] image_name:[linux-test] source_image_id:[Image-2N5XOLDfUb] vm_password:[xxxxxxxx] cleanup_nat:[false] cpu_amount:[0] memory_size_mb:[0]
==> pacloud: Start to configure the network ...
==> pacloud: Start to find or create VPC ..
==> pacloud: Found an existing VPC, name: HKX17011
==> pacloud: Start to find or create Network .. VPC ID: Vpc-5x2Epc0ism
==> pacloud: Found an existing Network, name: HKX17011DMZ
==> pacloud: Start to find or create Subnet..
==> pacloud: Found an existing Subnet, name: HKX17011DMZHKA001
==> pacloud: Start to configure the NAT ...
==> pacloud: Get NAT type ...
==> pacloud: NAT type successfully obtained, name: [by hour] Start to search or create NAT ...
==> pacloud: After searching or creating NAT
==> pacloud: NAT ID:Nat-yy9YwG6Bke
==> pacloud: Start creating bandwidth package, getting bandwidth package type ...
==> pacloud: The bandwidth package type is successfully obtained. Name: Start to obtain the operator list by hour ...
==> pacloud: The operator of the bandwidth package is successfully obtained. The name: HGC begins to create a bandwidth package ...
==> pacloud: The bandwidth package order is successfully created, and the order ID: Order-h1AwztRZTY starts to wait for the order status to be completed ...
==> pacloud: The bandwidth package order has been implemented, and the bandwidth package name: NAT-BW-X1700034 begins to obtain the bandwidth package details ...
==> pacloud: The bandwidth package details are obtained and successfully created. Start to create NAT IP ...
==> pacloud: The asynchronous task is created successfully, waiting for completion ...
==> pacloud: The NAT IP has been created. If you fail to obtain the details, you need to delete it manually
==> pacloud: NAT IP details obtained successfully, name: NAT-BW-IPX1700067
==> pacloud: NAT configuration completed
==> pacloud: Start to configure the security group
==> pacloud: The security group is configured
==> pacloud: Start to create ECS ...
==> pacloud: The ECS has been successfully created. Name: HKA-LX1700149
==> pacloud: Successfully obtained ECS details, ECS created
==> pacloud: Start to configure DNAT Rule
==> pacloud: DNAT Rule configuration completed
==> pacloud: Start adding ECS to security group ...
==> pacloud: Successfully added ECS to the security group
==> pacloud: Using ssh communicator to connect: 118.143.215.231
==> pacloud: Waiting for SSH to become available...
==> pacloud: Connected to SSH!
==> pacloud: Provisioning with shell script: C:\Users\ADMINI~1\AppData\Local\Temp\2\packer-shell686277403
pacloud: Loaded plugins: fastestmirror
pacloud: Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
pacloud: Determining fastest mirrors
pacloud: Resolving Dependencies
pacloud: --> Running transaction check
pacloud: ---> Package redis.x86_64 0:3.2.12-2.el7 will be installed
pacloud: --> Processing Dependency: libjemalloc.so.1()(64bit) for package: redis-3.2.12-2.el7.x86_64
pacloud: --> Running transaction check
pacloud: ---> Package jemalloc.x86_64 0:3.6.0-1.el7 will be installed
pacloud: --> Finished Dependency Resolution
pacloud:
pacloud: Dependencies Resolved
pacloud:
pacloud: ================================================================================
pacloud: Package Arch Version Repository Size
pacloud: ================================================================================
pacloud: Installing:
pacloud: redis x86_64 3.2.12-2.el7 epel 544 k
pacloud: Installing for dependencies:
pacloud: jemalloc x86_64 3.6.0-1.el7 epel 105 k
pacloud:
pacloud: Transaction Summary
pacloud: ================================================================================
pacloud: Install 1 Package (+1 Dependent package)
pacloud:
pacloud: Total download size: 648 k
pacloud: Installed size: 1.7 M
pacloud: Downloading packages:
pacloud: --------------------------------------------------------------------------------
pacloud: Total 953 kB/s | 648 kB 00:00
pacloud: Running transaction check
pacloud: Running transaction test
pacloud: Transaction test succeeded
pacloud: Running transaction
pacloud: Installing : jemalloc-3.6.0-1.el7.x86_64 1/2
pacloud: Installing : redis-3.2.12-2.el7.x86_64 2/2
pacloud: Verifying : redis-3.2.12-2.el7.x86_64 1/2
pacloud: Verifying : jemalloc-3.6.0-1.el7.x86_64 2/2
pacloud:
pacloud: Installed:
pacloud: redis.x86_64 0:3.2.12-2.el7
pacloud:
pacloud: Dependency Installed:
pacloud: jemalloc.x86_64 0:3.6.0-1.el7
pacloud:
pacloud: Complete!
==> pacloud: Start to close ECS
==> pacloud: ECS shutdown completed
==> pacloud: Start to create image
==> pacloud: Successfully created, image ID: Image-WB9sKza3Jj
==> pacloud: Start to move the ECS out of the security group. If it fails, please move out manually
==> pacloud: Move out successfully
==> pacloud: Start to clean up the DNAT rules, please delete manually if the deletion fails. DNAT Rule ID: NatDnatRule-HLWBaaA4HA
==> pacloud: DNAT rules are cleaned up
==> pacloud: Start to delete ECS, if the deletion fails, please manually delete. ECS name: HKA-LX1700149
==> pacloud: The status of ECS is Stopped | Shutdown, will try to delete directly
==> pacloud: ECS deleted successfully
==> pacloud: Start to clean the security group ...
==> pacloud: This execution creates a security group rule with ID: SecurityGroupRule-iKFRlu8B0p will try to delete, if the deletion fails, please manually delete
==> pacloud: Security Group Rules Succeed Delete
==> pacloud: No security group was created in this execution, no need to delete
==> pacloud: The security group is cleaned up
==> pacloud: Start to clean up NAT resources ...
==> pacloud: Found 2 NAT IPs and started cleaning ...
==> pacloud: Start to clean up the first NAT IP, IP: 118.143.215.231
==> pacloud: Deleted successfully
==> pacloud: Start to clean up the second NAT IP, IP: 118.143.215.154
==> pacloud: Deleted successfully
==> pacloud: After the NAT IP is cleaned up, the bandwidth packets are cleaned up. Bandwidth package: {NAT-BW-X1700034 1 1 Available | Available NatBandWidth-7NIiA3hqCp Hour | By hour packer 2019-06-17 11:34:04 HEMINGYE603 NatBrandWidthType-Hour}
==> pacloud: Bandwidth package is deleted successfully
==> pacloud: NAT resources are cleaned up
==> pacloud: Start to clean up Network resources ...
==> pacloud: No subnet was created in this execution, no need to delete
==> pacloud: No network was created in this execution, no need to delete
==> pacloud: No VPC was created in this execution, no need to delete
==> pacloud: Network resources are cleaned up
==> pacloud: The steps are all completed, try to get the image ID
==> pacloud: Successfully created, image ID: Image-WB9sKza3Jj
==> pacloud: End of construction, total time: 542 seconds
Build 'pacloud' finished.
==> Builds finished. The artifacts of successful builds are:
--> pacloud: Image has been created, image ID: 'Image-WB9sKza3Jj'</code></pre>
<p> </p>
Did the above content solve your problem?
Yes
No
Submitted successfully! Thank you for your feedback, we will try our best to do better and better!