主頁 > 知識庫 > Docker容器簡單部署nginx過程解析

Docker容器簡單部署nginx過程解析

熱門標簽:電銷機器人對公司貢獻 ai電銷機器人 如何開發(fā) 電話機器人服務差 蘭州語音電銷機器人軟件 山東400電話如何辦理 濟源電話外呼系統(tǒng)怎么樣 宿州防封外呼系統(tǒng)廠家 高德地圖標注在建線路 智能外呼系統(tǒng)如何部署

1、容器中部署nginx服務

centos:7鏡像運行一個容器,并且,在這個容器內(nèi)部署Nginx服務。

[root@Docker ~]# docker pull centos:7 //下載鏡像
[root@Docker ~]# docker run -itd --name webapp --restart=always centos:7 //運行一個容器名為:webapp
[root@Docker ~]# docker cp nginx-1.16.0.tar.gz webapp:/root //將本地nginx包導入webapp容器內(nèi)
[root@Docker ~]# docker exec -it webapp /bin/bash //進入容器
[root@85099880dabe ~]# tar zxf nginx-1.16.0.tar.gz
[root@85099880dabe ~]# cd nginx-1.16.0
[root@85099880dabe nginx-1.16.0]# yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel //下載相關(guān)依賴包
[root@85099880dabe nginx-1.16.0]# useradd -M -s /sbin/nologin nginx //添加一個沒有登錄權(quán)限的nginx用戶
[root@85099880dabe nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx //編譯安裝

[root@85099880dabe nginx-1.16.0]# make && make install //編譯安裝
[root@85099880dabe nginx-1.16.0]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ //創(chuàng)建軟鏈接
[root@85099880dabe nginx-1.16.0]# nginx
[root@85099880dabe nginx-1.16.0]# nginx //確認nginx服務開啟
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
[root@85099880dabe nginx-1.16.0]# cd /usr/local/nginx/html/
[root@85099880dabe html]# echo "TEST WEB" > index.html
[root@85099880dabe html]# curl 127.0.0.1
TEST WEB

2、遷移鏡像

所需環(huán)境:

docker1主機:192.168.45.129

docker2主機:192.168.45.134

1)docker1主機

將docker1的剛剛創(chuàng)建的容器并制作成鏡像導入docker2主機上

[root@Docker ~]# docker commit webapp myweb //將webapp容器制作成鏡像名為myweb
sha256:b035b8e8a36140e1bdbda9cf3a736b139ea8a48db7871a10f509b8f34d4c0f82
[root@Docker ~]# docker save > myweb.tar myweb:latest //將鏡像導出
[root@Docker ~]# scp myweb.tar 192.168.45.134:/root //將鏡像導出的tar包cp給docker2主機
The authenticity of host '192.168.45.134 (192.168.45.134)' can't be established.
ECDSA key fingerprint is d7:77:71:90:34:25:c0:ec:e0:b6:5c:cc:6b:44:93:7b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.45.134' (ECDSA) to the list of known hosts.
root@192.168.45.134's password: //密碼為docker2主機的密碼
myweb.tar 100% 353MB 176.4MB/s 00:02

2)docker2主機

[root@Docker2 ~]# docker load < myweb.tar //將剛剛cp過來的tar包制作成鏡像
[root@Docker2 ~]# docker run -itd --name newweb myweb:latest //啟動一個容器
[root@Docker2 ~]# docker exec -it newweb /bin/bash //進入容器
[root@4e419b580248 /]# nginx
[root@4e419b580248 /]# nginx //確定已啟動nginx服務
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@4e419b580248 /]# curl 127.0.0.1
TEST WEB

注:這里我們可以看見在docker1主機容器中搭建的簡單nginx環(huán)境并制作成鏡像成功的遷移到了docker2主機上了

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

標簽:南寧 畢節(jié) 晉中 云南 佛山 巴中 衡水 安陽

巨人網(wǎng)絡(luò)通訊聲明:本文標題《Docker容器簡單部署nginx過程解析》,本文關(guān)鍵詞  Docker,容器,簡單,部署,nginx,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Docker容器簡單部署nginx過程解析》相關(guān)的同類信息!
  • 本頁收集關(guān)于Docker容器簡單部署nginx過程解析的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章