您好,登錄后才能下訂單哦!
這篇文章主要講解了“如何使用docker-compose安裝軟件”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“如何使用docker-compose安裝軟件”吧!
mkdir -p /usr/local/docker
在/usr/local/docker/目錄下創(chuàng)建mysql目錄
mkdir -p /usr/local/docker/mysql
在/usr/local/docker/mysql目錄編寫docker-compose.yml文件
注:vi編輯器在命令模式輸入 set paste ,再輸入i 可以帶格式粘貼內(nèi)容到文件
version: '3.1' services: db: image: mysql restart: always environment: MYSQL_ROOT_PASSWORD: root command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 ports: - 3306:3306 volumes: - ./data:/var/lib/mysql adminer: image: adminer restart: always ports: - 9999:8080
運(yùn)行容器:docker-compose -f docker-compose.yml up -d
銷毀容器 docker-compose down
version: '3.1' services: web: image: 'twang2218/gitlab-ce-zh' restart: always hostname: '192.168.100.102' environment: TZ: 'Asia/Shanghai' GITLAB_OMNIBUS_CONFIG: | external_url 'http://192.168.100.102' gitlab_rails['gitlab_shell_ssh_port'] = 2222 unicorn['port'] = 8888 nginx['listen_port'] = 80 ports: - '8000:80' - '443:443' - '2222:22' volumes: - ./config:/etc/gitlab - ./data:/var/opt/gitlab - ./logs:/var/log/gitlab
啟動(dòng)后訪問(wèn):http://192.168.100.102
version: '3.1' services: nexus: restart: always image: sonatype/nexus3 container_name: nexus ports: - 8081:8081 volumes: - nexus-data:/nexus-data volumes: nexus-data:
啟動(dòng)后訪問(wèn):http://192.168.100.102:8081
maven使用nexus3
在setting.xml配置認(rèn)證信息,在<servers>節(jié)點(diǎn)添加如下配置:
<server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server>
在pom.xml添加部署配置
<distributionManagement> <repository> <id>releases</id> <name>Nexus Release Repository</name> <url>http://192.168.100.101:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://192.168.100.101:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
在pom.xml設(shè)置代理倉(cāng)庫(kù)
<repositories> <repository> <id>nexus</id> <name>Nexus Repository</name> <url>http://192.168.100.101:8081/repository/maven-public/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Nexus Plugin Repository</name> <url>http://192.168.100.101:8081/repository/maven-public/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </pluginRepository> </pluginRepositories>
配置pom.xml的build信息
<build> <finalName>myshop</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> <configuration> <skip>true</skip> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.4</version> <executions> <execution> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!-- 資源文件拷貝插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.1.0</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <!--Java 編譯插件--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- 打包時(shí)跳過(guò)測(cè)試 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build>
nexus 3中,已經(jīng)沒(méi)有了能對(duì)maven私服進(jìn)行deploy的默認(rèn)用戶,只有admin和匿名用戶。為了讓一個(gè)角色能夠?qū)aven進(jìn)行deploy,需要向它添加匿名角色所有權(quán)限和如下幾個(gè)權(quán)限:
4.1、下載安裝包:https://github.com/goharbor/harbor/releases
4.2、上傳到 /usr/local/docker/目錄
4.3、解壓 tar -zxvf harbor-offline-installer-v1.9.1-rc1.tgz
4.4、進(jìn)入到harbor目錄修改harbor.yml文件
hostname: 192.168.100.102 http: port: 8090 harbor_admin_password: Harbor12345
4.5、執(zhí)行 install.sh
啟動(dòng)后訪問(wèn):http://192.168.100.101:8090 用戶名:admin 密碼:Harbor12345
4.6、配置客戶端
##沒(méi)有此文件就創(chuàng)建 vim /etc/docker/daemon.json { "registry-mirrors":[ "https://registry.docker-cn.com" ], "insecure-registries":[ "192.168.100.101:8090" ] } 注意:該文件必須符合JSON規(guī)范,否則docker將不能啟動(dòng)
4.7、重啟服務(wù)
systemctl daemon-reload systemctl restart docker
4.8、檢查私服配置
docker info
4.9 、制作鏡像提交到harbor倉(cāng)庫(kù)
##拉取nginx docker pull nginx ## 在項(xiàng)目中標(biāo)記鏡像 ## docker tag SOURCE_IMAGE[:TAG] 192.168.100.101:8090/itchao-saas/IMAGE[:TAG] docker tag nginx:latest 192.168.100.101:8090/itchao-saas/nginx:latest ## 登錄 docker login 192.168.100.101:8090 -u admin -p Harbor12345 ## 推送鏡像到當(dāng)前項(xiàng)目 ## docker push 192.168.100.101:8090/itchao-saas/IMAGE[:TAG] docker push 192.168.100.101:8090/itchao-saas/nginx:latest
預(yù)先創(chuàng)建一個(gè)網(wǎng)絡(luò)
##創(chuàng)建網(wǎng)絡(luò) docker network create <Network Name> ##查看已存在的網(wǎng)絡(luò) docker network list
在docker-compose.yml中指定網(wǎng)絡(luò)
networks: default: external: name: myapp
version: '3.1' services: nginx: restart: always image: nginx ports: - 8080:80 - 80:80 - 443:443 volumes: - ./conf.d:/etc/nginx/conf.d - ./log:/var/log/nginx - ./www:/var/www - ./etc/letsencrypt:/etc/letsencrypt
感謝各位的閱讀,以上就是“如何使用docker-compose安裝軟件”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)如何使用docker-compose安裝軟件這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。