6.docker手動制作鏡像(基于C6)-創(chuàng)新互聯(lián)

1.制作一個基于centOS6版的Nginx鏡像(單服務(wù))

創(chuàng)新互聯(lián)憑借在網(wǎng)站建設(shè)、網(wǎng)站推廣領(lǐng)域領(lǐng)先的技術(shù)能力和多年的行業(yè)經(jīng)驗,為客戶提供超值的營銷型網(wǎng)站建設(shè)服務(wù),我們始終認為:好的營銷型網(wǎng)站就是好的業(yè)務(wù)員。我們已成功為企業(yè)單位、個人等客戶提供了網(wǎng)站設(shè)計、成都網(wǎng)站制作服務(wù),以良好的商業(yè)信譽,完善的服務(wù)及深厚的技術(shù)力量處于同行領(lǐng)先地位。

11.啟動并進入容器

[root@docker03 ]#  docker run -it -p 80:80 centos:6.9 /bin/bash
[root@9dac33fe6bda /]#

1.2更改容器系統(tǒng)的yum源和epel源

[root@9dac33fe6bda /]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0  17512      0 --:--:-- --:--:-- --:--:-- 17643
[root@9dac33fe6bda /]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   664  100   664    0     0   3179      0 --:--:-- --:--:-- --:--:--  3177

1.3安裝Nginx服務(wù)

[root@9dac33fe6bda /]# yum install -y nginx

1.4啟動nginx

[root@9dac33fe6bda /]# nginx

1.5測試

6.docker手動制作鏡像(基于C6)

1.6提交鏡像

[root@docker03 ~]# docker commit 9dac33fe6bda
sha256:b3b5ec6779bd43731aa3e1639811d1583a4404cb2296dab75a4f8c7e41d62b6a
[root@docker03 ~]# docker commit 9dac33fe6bda docker_centos6.9_nginx:v1
sha256:f954a629873f40f5b70676cc2618c4766b9ef161e4e46c38b89327b613662f4f
[root@docker03 ~]# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
docker_centos6.9_nginx   v1                  f954a629873f        7 seconds ago       446MB

1.7測試鏡像功能

[root@docker03 /opt]# docker run -d -p 80:80  -v /opt:/usr/share/nginx/html  docker_centos6.9_nginx:v1 nginx -g 'daemon off;  '
085ea855e734a0aa4aacb739b6de788f03e9d288bf16719fd1ad2e94de5896d0

6.docker手動制作鏡像(基于C6)

2.制作一個基于centOS版的可道云鏡像(多服務(wù))

2.1啟動并進入容器

[root@docker03 /opt]# docker run  -it  -p 80:80  centos:6.9 /bin/bash
[root@274ca61dd89f /]#

2.2更改容器系統(tǒng)的yum源和epel源

[root@274ca61dd89f /]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
110   664  110   664    0     0   4205      0 --:--:-- --:--:-- --:--:--  7545
[root@274ca61dd89f /]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0  25788      0 --:--:-- --:--:-- --:--:-- 61536

2.3安裝nginx

[root@274ca61dd89f /]# yum install nginx -y

2.4安裝PHP服務(wù)

[root@274ca61dd89f /]# yum install php-fpm php-gd php-mbstring -y

2.5更改PHP配置文件用戶和用戶組

[root@274ca61dd89f /]# vi /etc/php-fpm.d/www.conf

6.docker手動制作鏡像(基于C6)

2.6啟動PHP服務(wù)

[root@274ca61dd89f /]# service php-fpm start
Starting php-fpm:                                          [  OK  ]

2.7更改nginx的配置文件

添加到vi /etc/nginx/conf.d/default.conf 

#
# The default server
#

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /html;
    index  index.php  index.html index.htm;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

location ~ \.php$ {
    root           /html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /html$fastcgi_script_name;
    include        fastcgi_params;
}

2.8創(chuàng)建html目錄并下載可道云

[root@274ca61dd89f /]# mkdir /html
[root@274ca61dd89f html]# cd /html
[root@274ca61dd89f html]# curl -o kodexplorer4.40 http://static.kodcloud.com/update/download/kodexplorer4.40.zip
[root@274ca61dd89f html]# ls
kodexplorer4.40

2.9解壓可道云

[root@274ca61dd89f /]# install unzip -y
[root@274ca61dd89f /]# unzip kodexplorer4.40

2.10更改目錄的屬主屬組

[root@274ca61dd89f html]# chown -R nginx.nginx .
[root@274ca61dd89f html]# ll /html
total 13676
drwxr-xr-x 10 nginx nginx      115 Mar 21  2019 app
-rw-r--r--  1 nginx nginx    91248 Mar 21  2019 ChangeLog.md
drwxr-xr-x  3 nginx nginx       74 Mar 21  2019 config
drwxr-xr-x  7 nginx nginx       72 Mar 21  2019 data
-rw-r--r--  1 nginx nginx      118 Mar 21  2019 index.php
-rw-r--r--  1 nginx nginx 13894810 Dec 13 02:38 kodexplorer4.40
drwxr-xr-x 15 nginx nginx      218 Mar 21  2019 plugins
-rw-r--r--  1 nginx nginx     7718 Mar 21  2019 README.MD
drwxr-xr-x  6 nginx nginx       57 Mar 21  2019 static

2.11測試

6.docker手動制作鏡像(基于C6)

2.12編寫啟動腳本(夯住起動命令在最后一個啟動)

vi init.sh
#!/bin/bash
service php-fpm start
nginx -g 'daemon off;'
~

2.13生成鏡像

[root@docker03 /etc/nginx]# docker commit 274ca61dd89f docker_kod:v1
sha256:da72ea94c8cbf9f2c21b7655b4146b0308053c3988fc2b6d165a1f6dd4cbc8de

2.14測試鏡像

[root@docker03 ~]# docker run  -d -p 81:80 docker_kod:v1 /bin/bash /init.sh
cd5d18b69f1438426da1283160c73cbe45c2d8f73e74f5adeec0211bf14b52b7

6.docker手動制作鏡像(基于C6)
3.docker手動制作鏡像(基于C7)(Nginx+ssh)

3.1.創(chuàng)建并進入容器

[root@docker03 ~]# docker run -it -p 83:80 centos:7
[root@c919e69954a2 /]#

3.2.更改容器系統(tǒng)的yum源和epel源

[root@c919e69954a2 /]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
100  2523  100  2523    0     0  17831      0 --:--:-- --:--:-- --:--:-- 17893
[root@c919e69954a2 /]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   664  100   664    0     0   5044      0 --:--:-- --:--:-- --:--:--  5068

3.3.安裝nginx

[root@c919e69954a2 /]# yum install nginx -y

3.4.啟動服務(wù)

注:C7在容器中無法使用systemctl啟動服務(wù),因為bus進程沒有啟動,C7啟動快是因為多個進程同時啟動。

root@docker03 ~]# ps -ef |grep bus
dbus       6819      1  0 Dec12 ?        00:00:03 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root      43281  40267  0 11:09 pts/1    00:00:00 grep --color=auto bus

[root@c919e69954a2 /]# systemctl start nginx
Failed to get D-Bus connection: Operation not permitted

用手動啟動服務(wù)

[root@c919e69954a2 /]# systemctl start nginx
Failed to get D-Bus connection: Operation not permitted
[root@c919e69954a2 /]# systemctl cat nginx
# /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

/usr/sbin/nginx

3.5.安裝ssh服務(wù)

[root@c919e69954a2 /]# yum install openssh-server -y

3.6啟動sshd-keygen服務(wù)(因為沒有密鑰對,報錯)

[root@c919e69954a2 /]# /usr/sbin/sshd-keygen

/usr/sbin/sshd-keygen: line 10: /etc/rc.d/init.d/functions: No such file or directory

Generating SSH2 RSA host key: /usr/sbin/sshd-keygen: line 63: success: command not found

Generating SSH2 ECDSA host key: /usr/sbin/sshd-keygen: line 105: success: command not found

Generating SSH2 ED25519 host key: /usr/sbin/sshd-keygen: line 126: success: command not found

3.7在宿主機查詢文件對應(yīng)的軟件包

[root@docker01 ~]# rpm -qf /etc/rc.d/init.d/functions
initscripts-9.49.46-1.el7.x86_64

3.8安裝軟件包

[root@c919e69954a2 /]# yum install initscripts  -y

3.9在啟動sshd-keygen服務(wù),查看秘鑰對

[root@c1e50af6f42c /]# /usr/sbin/sshd-keygen
Generating SSH2 RSA host key:                              [  OK  ]
Generating SSH2 ECDSA host key:                            [  OK  ]
Generating SSH2 ED25519 host key:                          [  OK  ]
[root@c919e69954a2 /]# ls /etc/ssh/
moduli                    ssh_host_ecdsa_key.pub    ssh_host_ed25519_key.pub  ssh_host_rsa_key.pub      
ssh_host_ecdsa_key        ssh_host_ed25519_key      ssh_host_rsa_key          sshd_config

3.10啟動sshd服務(wù)

[root@c919e69954a2 /]# systemctl cat sshd
# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.service
Wants=sshd-keygen.service

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
[root@c919e69954a2 /]# /usr/sbin/sshd -D

3.11設(shè)置容器登錄密碼

echo '123456' | passwd  --stdin root

3.12連接測試

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

當前文章:6.docker手動制作鏡像(基于C6)-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://www.muchs.cn/article34/dpoope.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、域名注冊、網(wǎng)站收錄、品牌網(wǎng)站建設(shè)、商城網(wǎng)站、網(wǎng)站營銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作