Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a Docker Mirror

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to create a Docker image. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

1: create based on an existing image

The docker commit command is mainly used to create based on an existing scene. The essence is to package the running program in a container and the running environment of the program to generate a new image.

Command format: docker commit [options] Container ID/ name Warehouse name: [label]

Common command options:

-m: description information

-a: author information

-p: stop the container during the build process

Example:

First start an image, modify it in the container, and then generate a new image from the modified image. You need to remember the id number

[root@xyue ~] docker run-d httpd / bin/bash5c9edd4c9cc6f069bdc489b084530f450440f28db775f079add9dc191a69043d [root@xyue ~] docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES5c9edd4c9cc6 httpd "/ bin/bash" 7 seconds ago Exited (0) 5 seconds ago xenodochial_ Feynman [root @ xyue ~] docker commit-m "new"-a "docke" 5c9edd4c9cc6 docke:testsha256:06c816fc4ae8cea60eb49bcf23fd8803045dfb23561b7f32aeb82b7cbe1109db [root@xyue ~] docker images | grep dockedocke Test 06c816fc4ae8 49 seconds ago 178MB

Created based on a local template

A new image can be generated by importing the operating system template file, and the download address of the template:

[root@xyue ~] wget http://download.openvz.org/template/precreated/debian-7.0-x86-minimal.tar.gz[root@xyue ~] lsanaconda-ks.cfg debian-7.0-x86-minimal.tar.gz debian-7.8-x86-minimal.tar.gz Dockerfile [root@xyue ~] cat debian-7.0-x86-minimal.tar.gz | Image ID information is generated after successful import of docker import-daoke:newsha256:85b8caea781438cdc433f6fc2f60621e310e7e1706e1e6b29caa8d669dd7f971 [root@xyue ~] # docker images | grep newdaoke new 85b8caea7814 21 seconds ago 215MB

Create based on Dockerfile

Set up a working directory

[root@xyue ~] mkdir / apache

[root@xyue ~] cd / apache

Create and write Dockerfile files

[root@xyue apache] vim Dockerfile

# basic image centos based on

FROM centos

# maintain the user information of the image

MAINTAINER The CentOS Project

# Image operation instructions to install apachepackage

RUN yum-y update # and the new yum warehouse

RUN yum install-y httpd # install the apache service

# Open port 80

EXPOSE 80

# Simple startup script to avoid some issuse observed with container restart

# copy the home page of the website

ADD index.html / var/www/html/index.html

# copy the execution script to the image

ADD run.sh / run.sh

RUN chmod 755 / run.sh

# execute script when you start the container

CMD ["/ run.sh"]

Write and execute script content

[root@xyue apache] vim run.sh

#! / bin/bash

Rm-rf / run/httpd/* # / / clear httpd cache

Exec / usr/sbin/apachectl-D FOREGROUND # / / start the apache service

Create a test page

[root@xyue apache] # echo "web test" > index.html

[root@xyue apache] # cat index.html

Web test

[root@xyue apache] # ls

Dockerfile index.html run.sh

Note that the Dockerfile files in the above apache folder all use relative paths, so the startup script and the home page must be in the same folder as Dockerfile.

Use Dockerfile to generate an image

After writing the Dockerfile file, you can create an image through the docker build command.

Command format: docker build [option] path

Common options:

-t: specify the label information of the image

[root@xyue apache] docker build-t httpd:centos.

Omit

Installation

Process

Run the container with a new image

Load the newly generated image into the container to run

[root@xyue apache] # docker run-d-p 12580 httpd:centos

A38850819054c64f960dadf705912c4b59034b58c5933c3a160a40efaf731f0c

[root@xyue apache] # docker ps-a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

A38850819054 httpd:centos "/ run.sh" 9 seconds ago Up 8 seconds

The above is the editor for you to share how to create a Docker image, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report