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 manually build an image in docker

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Today, I will talk to you about how to build an image manually in docker. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.

View the local existing image:

[root@docker ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEnginx latest c59f17fe53b0 4 days ago 108MBubuntu latest 747cb2d60bbe 3 weeks ago 122MBcentos latest 196e0ce0c9fb 6 weeks ago 197MB

Now use the basic image centos to manually build a web service on this basis, here using nginx

Start a container and enter into the container:

[root@docker] # docker run-it-- name=web centos / bin/bash [root@bab3b6991467 /] #

Then install the nginx service in the container:

[root@bab3b6991467 /] # cd / usr/local/src/ [root@bab3b6991467 src] # yum install wget vim

Nginx is compiled and installed here, so download the nginx source package and install the compilation environment:

[root@bab3b6991467 src] # wget http://nginx.org/download/nginx-1.12.2.tar.gz

Compilation environment:

[root@bab3b6991467 src] # yum install gcc gcc-c++ glibc make autoconf openssl openssl-devel

Install some dependent packages for nginx:

[root@bab3b6991467 src] # yum install libxslt-devel-y gd gd-devel GeoIP GeoIP-devel pcre pcre-devel

Then the expense performs the installation:

[root@bab3b6991467 src] # lltotal 960 RW Murray. 1 root root 981687 Oct 17 13:20 nginx-1.12.2.tar.gz [root@bab3b6991467 src] # tar xf nginx-1.12.2.tar.gz [root@bab3b6991467 src] # cd nginx-1.12.2 [root@bab3b6991467 nginx-1.12.2] #. / configure-user=nginx-group=nginx-prefix=/usr/local/nginx-with-file-aio-with-http_ssl_module-with-http_realip_module-with-http_addition _ module-- with-http_xslt_module-- with-http_image_filter_module-- with-http_geoip_module-- with-http_sub_module-- with-http_dav_module-- with-http_flv_module-- with-http_mp4_module-- with-http_gunzip_module-- with-http_gzip_static_module-- with-http_auth_request_module-- with-http_random_index_module-- with-http_ Secure_link_module-with-http_degradation_module-with-http_stub_status_module

Create the users you need:

Useradd-M-s / sbin/nologin nginx

Continue to compile:

Make & & make installchown-R nginx:nginx / usr/local/nginx/

Here you need to introduce a parameter of the nginx command:

[root@bab3b6991467] # / usr/local/nginx/sbin/nginx-h-g directives: set global directives out of configuration file

-g: set directives for the configuration file of nginx

Now exit container and go back to host native

[root@bab3b6991467 ~] # exitexit

View the status of the container at this time:

[root@docker ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESbab3b6991467 centos "/ bin/bash" 37 minutes ago Exited (0) 21 seconds ago web

Use docker diff to see what changes have been made to the container. Because there is too much output, it will not be shown here.

Use docker commit to layer the web container to create a new image:

[root@docker ~] # docker commit-- help Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY [: TAG]] Create a new image from a container's changes-m,-- message string Commit message-a,-- author string Author (e.g., "John Hannibal Smith")

Starting now, commit:

[root@docker] # docker commit-m "compile nginx on centos" web wadeson/centos_nginx:v1sha256:210a202d37b8d2c31155c29adf0c7c0b49cfab7ff38234109919de7f4e76d1de

View the local image:

[root@docker ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEwadeson/centos_nginx v1 210a202d37b8 33 seconds ago 464MBnginx latest c59f17fe53b0 4 days ago 108MBubuntu latest 747cb2d60bbe 3 weeks ago 122MBcentos latest 196e0ce0c9fb 6 weeks ago 197MB

You can see the new image of docker commit just now, and now start a container to provide nginx service from this image:

[root@docker] # docker run-d-p80 wadeson/centos_nginx:v1 / usr/local/nginx/sbin/nginx-g "daemon off;" c12669357e2b09a05a396ac480a04dd1956303b784f894b615d4edb889a737ab

Then look at the container:

[root@docker ~] # docker ps-lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc12669357e2b wadeson/centos_nginx:v1 "/ usr/local/nginx/..." 41 seconds ago Up 40 seconds 0.0.0.0 usr/local/nginx/... 80-> 80/tcp thirsty_murdock

You can see that the nginx service is turned on, so access:

So the whole manual build was successful.

Explain some of the above commands:

Docker run-d-p80 usr/local/nginx/sbin/nginx 80 wadeson/centos_nginx:v1 / usr/local/nginx/sbin/nginx-g "daemon off;"

The following commands are all commands aimed at container. Since there is no setting of environment variables, the full path. The parameter nginx-g means that instructions can be added to the configuration file of nginx. Daemon off means that the nginx service does not run in the backend but in the foreground (the service in container must run in the foreground).

With docker top, you can view the running process of container:

[root@docker ~] # docker top c12669357e2bUID PID PPID C STIME TTY TIME CMDroot 35468 35451 02:55? 00:00:00 nginx: master process / usr/local/nginx/sbin/nginx-g daemon off 1000 35489 35468 0 02:55? 00:00:00 nginx: worker process

Use docker exec to enter the container:

[root@docker ~] # docker exec-it c12669357e2b / bin/bash [root@c12669357e2b /] # ps-efUID PID PPID C STIME TTY TIME CMDroot 1 00 06:55? 00:00:00 nginx: master process / usr/local/nginx/sbin/nginx-g daemon off Nginx 5 1 0 06:55? 00:00:00 nginx: worker processroot 6 01 07:01 pts/0 00:00:00 / bin/bashroot 20 60 07:01 pts/0 00:00:00 ps-ef after reading the above, do you have any further understanding of how to manually build an image in docker? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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