導航:首頁 > 配伺服器 > 如何配置docker伺服器

如何配置docker伺服器

發布時間:2022-04-26 06:43:12

❶ 如何在伺服器上部署docker

Debian / Ubuntu

  1. sudo apt update

  2. sudo apt install docker.io

  3. sudo systemctl enable docker

  4. sudo systemctl start docker

RedHat / CentOS

  1. sudo yum update

  2. sudo yum install docker.io

  3. sudo systemctl enable docker

  4. sudo systemctl start docker

❷ 如何在linux伺服器上安裝Docker

安裝一個docker,然後自己用命令行啟動另外一個docker
下面是一個啟動命令:
<pre t="code" l="bash">nohup docker daemon --selinux-enabled=false --log-driver=journald --storage-driver=overlay \
-H unix:///var/run/docker-bootstrap.sock -p /var/run/dockerbootstrap.pid \
--iptables=false --ip-masq=false --bridge=none --graph=/var/lib/dockerbootstrap \
2> /var/log/docker-bootstrap.log 1> /dev/null
注意幾點:-H參數需要給出另外一個socket文件名-p給出另外一個pid文件名--graph 給出另外一個存放docker鏡像容器的路徑名稱

❸ 如何部署 Docker Registry 服務 第2頁

將創建一個 Container 來運行 Docker 的官方 Registry 鏡像。你將推送(Push)一個鏡像到這個 Registry 伺服器,然後再從該 Registry 中拉取(Pull)同一個鏡像。

這是個很好的練習,有助於理解客戶端與本地 Registry 的基本交互。

1、安裝 Docker。

2、從 Docker 公共 Registry 中運行 hello-world 鏡像。

$ docker run hello-world
run 命令自動從 Docker 的官方鏡像庫中將 hello-world 鏡像 pull 下來。

3、在 localhost 上啟動 Registry 服務。

$ docker run -p 5000:5000 registry:2.0
這將在 DOCKER_HOST 上啟動一個 Registry 服務,並在 5000 埠監聽。
4、列出鏡像。

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe923 3 days ago 545.1 MB
golang 1.4 121a93c90463 5 days ago 514.9 MB
hello-world latest e45a5af57b00 3 months ago 910 B
這個列表應當包括一個由先前運行而得來的 hello-world 鏡像。

5、為本地 repoistory 重新標記 hello-world 鏡像。

$ docker tag hello-world:latest localhost:5000/hello-mine:latest
此命令使用
[REGISTRYHOST/]NAME[:TAG] 格式為 hello-world:latest 重新打標。REGISTRYHOST在此例中是
localhost。在 Mac OSX 環境中,得把 localhost 換成 $(boot2docker ip):5000。

6、列出新鏡像。

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe923 3 days ago 545.1 MB
golang 1.4 121a93c90463 5 days ago 514.9 MB
hello-world latest e45a5af57b00 3 months ago 910 B
localhost:5000/hello-mine latest ef5a5gf57b01 3 months ago 910 B
可以看到,新鏡像已經出現在列表中。

7、推送新鏡像到本地 Registry 中。

$ docker push localhost:5000/hello-mine:latest
The push refers to a repository [localhost:5000/hello-mine] (len: 1)
e45a5af57b00: Image already exists
31cbccb51277: Image successfully pushed
511136ea3c5a: Image already exists
Digest: sha256:
8、使用 curl 命令及 Docker Registry 服務 API v2 列出 Registry 中的鏡像

❹ 不同操作系統Docker環境要求不同,如何快速部署

其實可以把問題報給客戶,要求用戶所有的電腦統一操作系統,然後再安裝這個doctor,這樣的環境就統一了,最好在安裝之前把系統重做一次,用純凈的操作系統部署起來就更加快捷便利。

❺ 如何操作docker 容器的配置文件

步驟1:為我們的容器創建第一個鏡像
# 以 centos 鏡像作為基礎鏡像,我們啟動自己的容器並在其中執行/bin/bash命令
# 註:-t -i 參數用於創建一個虛擬的命令行。
sudo docker run -t -i centos /bin/bash
現在我們已經成功的運行了自己的第一個容器,並且進入到容器的命令行界面中。在容器中,我們執行下面的命令:

yum -y update # 更新軟體包
yum install which # 安裝which命令
yum install git # 安裝Git

安裝完成後,按 Ctrl + d 來退出容器的命令行。
# 執行sudo docker ps -a,可以看到被我們終止的容器
CONTAINER ID IMAGE COMMAND CREATED……
da9031d3568f centos:6.4 /bin/bash 5 minutes ago…..
把我們所做的改變提交到一個新的容器:
# 這里我們創建一個自己的基礎容器,容器中安裝好了文章中所需的常用工具。讀者的容器 id 可能與文章中的有所不同,以上一步 docker ps -a 的結果為准。
sudo docker commit da90 custom/base
容器成功提交後,執行 sudo docker images ,我們會看到剛才提交的容器(如下面的結果所示)。我們就以這個容器為基礎容器,再來創建一個新的容器。
REPOSITORY TAG IMAGE ID CREATED
custom/base latest 05b6cecd370b 2 minutes ago
centos 6.4 539c0211cd76 10 months ago
centos latest 539c0211cd76 10 months ago…
步驟2:創建新的容器,並安裝 apache
# 以 custom/base 容器為基礎,運行一個新的容器。

sudo docker run -t -i custom/base /bin/bash

# 安裝 httpd

yum install httpd

步驟3:再次提交新的容器
按 Ctrl + d 來退出容器的命令行,然後執行命令:
# 這個命令會把步驟2中我們安裝 httpd 帶來的改變提交到新的名為 custom/httpd 的容器鏡像中。你的容器 id 可能會和文章中有所不同,以 sudo docker ps -a 命令的結果為准。

sudo docker commit aa6e2fc0b94c custom/httpd

你應該已經發現了,我們創建了一個帶有 http 伺服器並可以復用的容器鏡像。你可以根據這種思想,為自己所需的每個組件都創建一個容器,然後把這些容器復用於開發環境或者生產環境。
步驟7:運行 http 伺服器
# -v will Mount a volume from VM to the container which was also shared from host to Vagrant VM.
# -v 參數把主機共享給虛擬機的一個卷掛載到容器中
# -p forward VM port 80 to container port 80; VM port 80 is mapped to host port 8080 in Vagrantfile
# -p 參數把虛擬機的80埠映射到容器的80埠;虛擬機的80埠在 Vagrantfile 中被綁定到主機的8080埠,也就是:主機8080->虛擬機80->容器80
sudo docker run -t -i -p 80:80 -v /vagrant/htdocs:/var/www/html custom/httpd /bin/bash
# 啟動 Apache
apachectl -k start

❻ 如何創建一個docker service 服務

1. 運行一個Docker實例
Docker首先會嘗試從本地取得並運行所需的鏡像,如果在本地主機上沒有發現,它就會從Docker公共注冊中心拉取。這里,我們將會拉取鏡像並在 Docker 容器中創建一個Fedora實例,並連接到它的 tty 上的bash shell。
# docker run -i -t fedora bash

2.安裝Apache網路伺服器
現在,在我們的Fedora基本鏡像實例准備好後,我們將會開始互動式地安裝Apache網路伺服器,而不是為它創建Dockerfile。為了做到這點,我們需要在終端或者shell運行以下命令。
# yum update

# yum install httpd

退出容器的 tty。
# exit

3.保存鏡像
現在,我們要去保存在Fedora實例里做的修改。要做到這個,我們首先需要知道實例的容器ID。而為了得到ID,我們又需要運行以下命令(LCTT 譯註:在容器外執行該命令)。
# docker ps -a

然後,我們會保存這些改變為一個新的鏡像,請運行以下命令。
# docker commit c16378f943fe fedora-httpd

這里,修改已經通過使用容器ID保存起來了,鏡像名字叫fedora-httpd。為了確認新的鏡像是否在運行,我們將運行以下命令。
# docker images

4. 添加內容到新的鏡像
我們自己新的Fedora Apache鏡像正成功的運行,現在我們想添加一些我們網站的網頁內容到Apache網路伺服器,使得網站能夠開箱即用。為做到這點,我們需要創建一個新的Dockerfile,它會處理從復制網頁內容到啟用80埠的所有操作。要達到這樣的目的,我們需要使用我們最喜歡的文本編輯器創建Dockerfile文件,像下面演示的一樣。
# nano Dockerfile
現在,我們需要添加以下的命令行到文件中。
FROM fedora-httpd
ADD mysite.tar /tmp/
RUN mv /tmp/mysite/* /var/www/html
EXPOSE 80
ENTRYPOINT [ "/usr/sbin/httpd" ]
CMD [ "-D", "FOREGROUND" ]

這里,上述的Dockerfile中,放在mysite.tar里的網頁內容會自動解壓到/tmp/文件夾里。然後,整個站點會被移動到Apache的網頁根目錄/var/www/html/,命令expose 80會打開80埠,這樣網站就能正常訪問了。其次,入口點放在了/usr/sbin/https裡面,保證Apache伺服器能夠執行。

5. 構建並運行一個容器
現在,我們要用剛剛創建的Dockerfile創建我們的容器,以便將我們的網站添加到上面。為做到這,我們需要運行以下命令。
# docker build -rm -t mysite .

建立好我們的新容器後,我們需要要用下面的命令來運行容器。
# docker run -d -P mysite

❼ 如何部署 Docker Registry 服務

官方鏡像下的簡單示例

本節中,將創建一個 Container 來運行 Docker 的官方 Registry 鏡像。你將推送(Push)一個鏡像到這個 Registry 伺服器,然後再從該 Registry 中拉取(Pull)同一個鏡像。

這是個很好的練習,有助於理解客戶端與本地 Registry 的基本交互。

1、安裝 Docker。

2、從 Docker 公共 Registry 中運行 hello-world 鏡像。

$ docker run hello-world
run 命令自動從 Docker 的官方鏡像庫中將 hello-world 鏡像 pull 下來。

3、在 localhost 上啟動 Registry 服務。

$ docker run -p 5000:5000 registry:2.0
這將在 DOCKER_HOST 上啟動一個 Registry 服務,並在 5000 埠監聽。
4、列出鏡像。

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe923 3 days ago 545.1 MB
golang 1.4 121a93c90463 5 days ago 514.9 MB
hello-world latest e45a5af57b00 3 months ago 910 B
這個列表應當包括一個由先前運行而得來的 hello-world 鏡像。

5、為本地 repoistory 重新標記 hello-world 鏡像。

$ docker tag hello-world:latest localhost:5000/hello-mine:latest
此命令使用 [REGISTRYHOST/]NAME[:TAG] 格式為 hello-world:latest 重新打標。REGISTRYHOST在此例中是 localhost。在 Mac OSX 環境中,得把 localhost 換成 $(boot2docker ip):5000。

6、列出新鏡像。

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe923 3 days ago 545.1 MB
golang 1.4 121a93c90463 5 days ago 514.9 MB
hello-world latest e45a5af57b00 3 months ago 910 B
localhost:5000/hello-mine latest ef5a5gf57b01 3 months ago 910 B
可以看到,新鏡像已經出現在列表中。

7、推送新鏡像到本地 Registry 中。

$ docker push localhost:5000/hello-mine:latest
The push refers to a repository [localhost:5000/hello-mine] (len: 1)
e45a5af57b00: Image already exists
31cbccb51277: Image successfully pushed
511136ea3c5a: Image already exists
Digest: sha256:
8、使用 curl 命令及 Docker Registry 服務 API v2 列出 Registry 中的鏡像:

$ curl -v -X GET http://localhost:5000/v2/hello-mine/tags/list* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...* Connected to localhost (127.0.0.1) port 5000 (#0)> GET /v2/hello-mine/tags/list HTTP/1.1> User-Agent: curl/7.35.0> Host: localhost:5000> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< Date: Sun, 12 Apr 2015 01:29:47 GMT
< Content-Length: 40
<
{"name":"hello-mine","tags":["latest"]}
* Connection #0 to host localhost left intact
也可以通過在瀏覽器中訪問以下地址來獲取這些信息:http://localhost:5000/v2/hello-mine/tags/list

9、從你的本地環境中移除所有未使用的鏡像:

$ docker rmi -f $(docker images -q -a )
此命令僅用於說明目的;移除鏡像強制 run 從 Registry 而不是從本地緩存拉取。如果在這之後運行docker images,在你的鏡像列表中,應該看不到任何 hello-world 或 hello-mine 的實例。

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe923 3 days ago 545.1 MB
golang 1.4 121a93c90463 5 days ago 514.9 MB
10、試運行 hello-mine。

$ docker run hello-mine
Unable to find image 'hello-mine:latest' locally
Pulling repository hello-mine
FATA[0001] Error: image library/hello-mine:latest not found
命令 run 運行失敗,因為你的新鏡像在 Docker 公共 Registry 中是不存在的。
11、現在,嘗試指定鏡像的 Registry 來運行鏡像:

$ docker run localhost:5000/hello-mine
如果你在這之後運行 docker images, 你會發現裡面多了一個 hello-mine 的實例。

使 Docker 官方 Registry 鏡像做好生產環境准備

Docker 的官方鏡像只為簡單的測試或除錯准備。其配置對多數生產環境來講都不適用。例如,任何能訪問伺服器 IP 的客戶端,都能推送及拉取鏡像。參看下一節,獲取使該鏡像做好生產環境准備的信息。

理解生產環境的部署

當部署一個用於生產環境發布的 Registry 時,須考慮如下因素:

BACKEND STORAGE 應在何處存儲鏡像?
ACCESS AND/OR AUTHENTICATION 用戶是否應擁有全部或受控的訪問許可權?這取決於你為公眾提供鏡像服務,還是只為公司內部提供。
DEBUGGING 當問題或狀況發生時,是否有解決這些它們的方法。日誌由於可以看到問題動向,這使其很有用。
CACHING 快速提取鏡像可能至關重要,如果依賴鏡像進行測試、構建,或有其他自動化系統的話。
我們可以配置 Registry 功能特性,用以調整適配這些因素。可以在命令行里指定選項來干這個,或者更通常地,用一個 Registry 配置文件來完成此事。配置文件是 YAML 格式的。

Docker 的官方 Repository 鏡像用以下配置文件做了預置:

version: 0.1
log:
level: debug
fields:
service: registry
environment: development
storage:
cache:
layerinfo: inmemory
filesystem:
rootdirectory: /tmp/registry-dev
http:
addr: :5000
secret: asecretforlocaldevelopment
debug:
addr: localhost:5001
redis:
addr: localhost:6379
pool:
maxidle: 16
maxactive: 64
idletimeout: 300s
dialtimeout: 10ms
readtimeout: 10ms
writetimeout: 10ms
notifications:
endpoints:
- name: local-8082
url: http://localhost:5003/callback
headers:
Authorization: [Bearer <an example token>]
timeout: 1s
threshold: 10
backoff: 1s
disabled: true
- name: local-8083
url: http://localhost:8083/callback
timeout: 1s
threshold: 10
backoff: 1s
disabled: true
這個配置非常基本,可以看到這在生產環境下會有一些問題。例如,http 區塊詳述了運行 Registry 的主機的 HTTP 伺服器配置,但伺服器沒有使用甚至是最低要求的傳輸層安全性(TLS)配置。接下來我們將配置這些東西。

❽ 如何搭建及使用docker registry

registry是什麼?
registry是Docker的鏡像存儲服務,docker hub上的registry鏡像見Registry官方鏡像,更多詳細信息請參見源碼
搭建registry
在伺服器上執行如下命令安裝docker,這里選擇騰訊雲(Ubuntu Server 14.04.1 LTS 64位)鏡像來創建伺服器
curl -fsSL https://get.docker.com/ | sh

安裝docker-compose Docker Compose是一個定義及運行多個Docker容器的工具。使用Docker Compose只需要在一個配置文件中定義多個Docker容器,然後使用一條命令將多個容器啟動,Docker Compose會通過解析容器間的依賴關系,按先後順序啟動所定義的容器。詳見Docker Compose
curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-$(uname -s)-$(uname -m) > /usr/local/bin/docker-compose
chmod a+x /usr/local/bin/docker-compose

啟動registry服務,此例中包含nginx和registry兩個容器,涉及的包及配置文件請參見附件,解壓後,直接執行如下命令即可創建服務。
docker-compose up -d

停止服務
docker-compose stop

重啟服務
docker-compose restart

下線服務
docker-compose down

上傳鏡像
因為上面搭建的registry服務是http的,所以docker啟動參數需要配置--insecure-registry localhost選項,修改/etc/default/docker文件
DOCKER_OPTS="--insecure-registry localhost"

重啟docker
service docker restart

拉取上傳鏡像 docker pull;docker tag;docker push(tag默認為latest)
docker pull hello-world
docker tag hello-world localhost/library/hello-world
docker push localhost/library/hello-world

下載鏡像
docker pull localhost/library/hello-world

刪除鏡像
docker rmi localhost/library/hello-world

獲取鏡像倉庫列表
# curl http://localhost/v2/_catalog
{"repositories":["library/hello-world"]}

未上傳鏡像前的輸出如下:
# curl http://localhost/v2/_catalog
{"repositories":[]}

獲取鏡像tag列表
# curl -X GET http://localhost/v2/library/hello-world/tags/list
{"name":"library/hello-world","tags":["latest"]}

獲取鏡像manifests信息
# curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET http://localhost/v2/library/hello-world/manifests/latest
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"size": 1473,
"digest": "sha256:"
},
"layers": [
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 974,
"digest": "sha256:"
}
]
}

其中即為執行docker images時看到的IMAGE ID。 layers表示了鏡像的層次關系,可以通過layers中的digest來拉取blob,見下面獲取鏡像blob
獲取鏡像blob
在上面獲取hello-world:latest鏡像的manifests信息中可以看到其只有一個layer,以此為例來看如何獲取鏡像blob。從拉取的結果可以看到獲取的blob與文件sha256是一致的。執行docker pull實際上就是首先獲取到鏡像的manifests信息後,再拉取blob的。
# curl -s -X GET http://localhost/v2/library/hello-world/blobs/sha256: -o hello-world.blob
# ls -l hello-world.blob
-rw-r--r-- 1 root root 974 Nov 23 09:56 hello-world.blob
# sha256sum hello-world.blob
hello-world.blob

##刪除鏡像(soft delete)
首先通過curl -i 參數獲取到鏡像的Docker-Content-Digest,registry 2.3及以後的版本必須在header中指定Accept: application/vnd.docker.distribution.manifest.v2+json,否則默認返回的是schema1的digest,其與schema2的digest不同,使用不指定上述頭信息返回的digest刪除時會返回404。
# curl -i -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET http://localhost/v2/library/hello-world/manifests/latest

HTTP/1.1 200 OK
Server: nginx/1.11.5
Date: Wed, 23 Nov 2016 02:17:51 GMT
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Content-Length: 524
Connection: keep-alive
Docker-Content-Digest: sha256:
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:"

{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"size": 1473,
"digest": "sha256:"
},
"layers": [
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 974,
"digest": "sha256:"
}
]
}

根據上一步返回的Docker-Content-Digest刪除,返回202表示刪除成功
# curl -k -v -s -X DELETE http://localhost/v2/library/hello-world/manifests/sha256:

* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> DELETE /v2/library/hello-world/manifests/sha256: HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost
> Accept: */*
>
< **HTTP/1.1 202 Accepted**
* Server nginx/1.11.5 is not blacklisted
< Server: nginx/1.11.5
< Date: Wed, 23 Nov 2016 02:29:59 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 0
< Connection: keep-alive
< Docker-Distribution-Api-Version: registry/2.0
<
* Connection #0 to host localhost left intact

確認結果
# curl -X GET http://localhost/v2/library/hello-world/tags/list
{"name":"library/hello-world","tags":null}

刪除鏡像(hard delete)
在上一步中,只是刪除了鏡像的manifests信息,解引用的blob還在佔用磁碟空間,執行如下命令可以查看可以刪除的blob
docker exec -it myregistry_registry_1 /bin/registry garbage-collect --dry-run /etc/registry/config.yml

要刪除blob,釋放磁碟空間,需要執行下面的命令。需要特別注意的是在執行下面的命令時registry必須是只讀模式(只讀模式可在registry配置文件中設置),否則可能會導致數據不一致。
docker exec -it myregistry_registry_1 /bin/registry garbage-collect /etc/registry/

閱讀全文

與如何配置docker伺服器相關的資料

熱點內容
做解壓的解壓球 瀏覽:563
伺服器地址怎麼改id 瀏覽:454
用紙做解壓器手工 瀏覽:516
如何配置本地域名伺服器 瀏覽:563
誠信可靠的重慶伺服器託管雲空間 瀏覽:977
怎樣找到用應用鎖加密的應用 瀏覽:590
百戰程序員解說 瀏覽:758
吃雞安卓怎麼遇到真人 瀏覽:20
python最好的開發工具 瀏覽:227
有關命令應用文模板 瀏覽:978
epma指標組合源碼圖片 瀏覽:884
屏幕上小圓圈怎麼取消安卓 瀏覽:342
數控車r30凹弧怎樣編程 瀏覽:653
孩子王app會員卡在哪裡看 瀏覽:315
程序員新技術教學視頻 瀏覽:717
歡太健康APP設備在哪裡 瀏覽:791
跟客戶溝通壓力大怎麼樣排解壓力 瀏覽:948
域伺服器為什麼沒有重啟選擇 瀏覽:616
智能雲伺服器如何租用 瀏覽:682
51單片機的針腳電壓是多少 瀏覽:281