Get the App
SLTechnology News&Howtos  ›  Servers  › 

How many methods are there to create docker images

Shulou Source: shulou.com Published: 2022-06-03 04:17:35 10月17日 Update

How many methods are there to create docker images? To solve this problem, today the editor summarizes this article on the creation of docker images, hoping to help more friends who want to solve this problem to find a more simple and easy way.

There are three ways to create an image: based on an existing image, based on a local template, and based on docker.

Create based on an existing image

Creating based on an existing image mainly uses the docker commit command

Common options:

-m: description information

-a: author information

-p: stop the container during the build process

Command format

Docker commit [options] Container id/ name Warehouse name: [label]

Created based on a local template

An image can be generated by importing the operating system template file. The template can be downloaded from the OPENVZ open source project at http://openvz.org/Download/template/precreated

Download the ubuntu template package and import it as a local image using the docker import command

Create based on dockerfile

The dockerfile structure is roughly divided into four parts: basic image information, maintainer information, mirror operation instructions and instructions executed when the container starts.

# Import a centos container in advance

1. Create a working directory

two。 Create and write dockerfile files

3. Write and execute script content

4. Create a test web page

5. Use dockerfile to generate an image

After writing dockerfile and related content, you can use the docker build command to create a mirror

Command format

Docker build [option] path

Common option

-t specifies the label information of the image

# Last point. Represents the current path.

6. Run the container with a new image

-p 12345 80 means to map port 80 to local port 12345

Finally, you can use web access to test it.

If you can read this, congratulations, you already have the most practical experience of how to create docker images. If you want to read more related articles, you are welcome to follow the industry information channel!

Tags: Images information commands containers templates methods content generation names commonly used instructions files articles more tags formats ports web pages paths questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL macOS Shulou Tech Info Linux