linux使用docker-compose部署軟件配置詳解
前言
本篇將分享一些 docker-compose 的配置,可參考其總結(jié)自己的一套基于docker的開發(fā)/生產(chǎn)環(huán)境配置。下面話不多說了,來一起看看詳細(xì)的介紹吧
安裝docker及docker-compose
install docker
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
install docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
創(chuàng)建專屬網(wǎng)絡(luò)
使用 docker network 創(chuàng)建自己的專屬常用網(wǎng)絡(luò) me_gateway,使得 docker 的軟件能夠互相訪問
docker network create me_gateway
docker-compose 部署 Traefik
一個反向代理服務(wù)器,它非常快,有自動發(fā)現(xiàn)服務(wù),自動申請 https 等非常棒的特性,項(xiàng)目地址,中文文檔。
docker-compose.yml
這是一個使用 traefik 的 docker-compose.yml 配置示例
其中,掛載的 ./traefik.toml 為其配置,
掛載的 acme.json 為 Let's Encrypt 的配置
version: '3'
version: '3' services: me_traefik: image: traefik:1.7.4 container_name: me_traefik ports: - '80:80' - '443:443' - '8090:8090' volumes: - /var/run/docker.sock:/var/run/docker.sock - ./traefik.toml:/traefik.toml - ./acme.json:/acme.json networks: - webgateway networks: webgateway: external: name: me_gateway
traefik.toml
配置詳細(xì)說明:http://docs.traefik.cn/toml#acme-lets-encrypt-configuration
以下為一個示例,在配置驗(yàn)證的時候遇到一些問題,可參考下面配置或者這篇文章的評論
################################################################ # Global configuration ################################################################ # Enable debug mode # # Optional # Default: false # debug = false # Log level # # Optional # Default: "ERROR" # logLevel = "ERROR" # Entrypoints to be used by frontends that do not specify any entrypoint. # Each frontend can specify its own entrypoints. # # Optional # Default: ["http"] # defaultEntryPoints = ["http","https"] ################################################################ # Entrypoints configuration ################################################################ # Entrypoints definition # # Optional # Default: # 要為一個入口點(diǎn)開啟基礎(chǔ)認(rèn)證(basic auth) # 使用2組用戶名/密碼: test:test 與 test2:test2 # 密碼可以以MD5、SHA1或BCrypt方式加密:你可以使用htpasswd來生成這些用戶名密碼。 # [entryPoints] # [entryPoints.http] # address = ":80" # [entryPoints.http.auth.basic] # users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"] # # 要為一個入口點(diǎn)開啟摘要認(rèn)證(digest auth) # 使用2組用戶名/域/密碼: test:traefik:test 與 test2:traefik:test2 # 你可以使用htdigest來生成這些用戶名/域/密碼 [entryPoints] [entryPoints.http] address = ":80" # [entryPoints.http.redirect] # entryPoint = "https" [entryPoints.https] address = ":443" [entryPoints.https.tls] [entryPoints.webentry] address = ":8090" [entryPoints.webentry.auth] [entryPoints.webentry.auth.basic] users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"] ################################################################ # API and dashboard configuration ################################################################ # Enable API and dashboard [api] dashboard = true entrypoint = "webentry" ################################################################ # Ping configuration ################################################################ # Enable ping [ping] # Name of the related entry point # # Optional # Default: "traefik" # # entryPoint = "traefik" ################################################################ # Docker 后端配置 ################################################################ # 使用默認(rèn)域名。 # 可以通過為容器設(shè)置"traefik.domain" label來覆蓋。 # 啟用Docker后端配置 [docker] endpoint = "unix:///var/run/docker.sock" domain = "yimo.link" watch = true exposedByDefault = false usebindportip = true swarmMode = false network = "me_gateway" [acme] email = "yimo666666@qq.com" storage = "acme.json" entryPoint = "https" onDemand = false onHostRule = true [acme.httpChallenge] entryPoint="http"
docker-compose 部署 Gogs,并使用 traefik 綁定域名
如果想要與 mysql 一起構(gòu)建,可參考此配置
docker-compose.yml
version: '3' services: me_gogs: restart: always image: gogs/gogs container_name: me_gogs volumes: - ./data:/data - ./logs:/app/gogs/log ports: - '10022:22' - '10080:3000' labels: - 'traefik.backend=me_gogs' - 'traefik.frontend.rule=Host:git.yimo.link' - 'traefik.enable=true' - 'traefik.protocol=http' - 'traefik.port=3000' networks: - webgateway networks: webgateway: external: name: me_gateway
初始化時需要將域名設(shè)置為 0.0.0.0 或者git.yimo.link
即 ./data/gogs/conf/app.ini 項(xiàng)為
DOMAIN = git.yimo.link
docker-compose 部署 mysql
這個值得說明的就是,同一網(wǎng)絡(luò)下,可直接使用 me_mysql 連接
docker-compose.yml
version: '3' services: me_mysql: image: mysql:5.7.21 container_name: me_mysql volumes: - ./data:/var/lib/mysql ports: - '3306:3306' environment: - MYSQL_ROOT_PASSWORD=root networks: - webgateway networks: webgateway: external: name: me_gateway
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關(guān)文章
ubuntu18.04獲取root權(quán)限并用root用戶登錄的實(shí)現(xiàn)
這篇文章主要介紹了ubuntu18.04獲取root權(quán)限并用root用戶登錄的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12移植busybox構(gòu)建最小根文件系統(tǒng)的步驟詳解
這篇文章主要介紹了移植busybox構(gòu)建最小根文件系統(tǒng)的步驟,本文分為五部給大家介紹的非常詳細(xì),需要的朋友可以參考下2019-07-07Linux下利用python實(shí)現(xiàn)語音識別詳細(xì)教程
早期語音識別系統(tǒng)僅能識別單個講話者以及只有約十幾個單詞的詞匯量?,F(xiàn)代語音識別系統(tǒng)已經(jīng)取得了很大進(jìn)步,對于 Python 使用者而言,一些語音識別服務(wù)可通過 API 在線使用,且其中大部分也提供了 Python SDK,感興趣的小伙伴可以參考閱讀2023-03-03win2003下PHP使用preg_match_all導(dǎo)致apache崩潰問題的解決方法
這篇文章主要介紹了win2003下PHP使用preg_match_all導(dǎo)致apache崩潰問題的解決方法,詳細(xì)的分析了問題產(chǎn)生原因以及解決方案,需要的朋友可以參考下2014-07-07Linux虛擬機(jī)修改ip地址,查看網(wǎng)關(guān),網(wǎng)絡(luò)環(huán)境配置的教程
這篇文章主要介紹了Linux虛擬機(jī)修改ip地址,查看網(wǎng)關(guān),網(wǎng)絡(luò)環(huán)境配置的教程,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11