mkdir -p /usr/local/docker
在/usr/local/docker/目錄下建立mysql目錄mysql
mkdir -p /usr/local/docker/mysql
在/usr/local/docker/mysql目錄編寫docker-compose.yml文件nginx
注:vi編輯器在命令模式輸入 set paste ,再輸入i 能夠帶格式粘貼內容到文件git
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
運行容器:docker-compose -f docker-compose.yml up -dgithub
銷燬容器 docker-compose downweb
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
啓動後訪問:http://192.168.100.102spring
version: '3.1' services: nexus: restart: always image: sonatype/nexus3 container_name: nexus ports: - 8081:8081 volumes: - nexus-data:/nexus-data volumes: nexus-data:
啓動後訪問:http://192.168.100.102:8081sql
maven使用nexus3docker
在setting.xml配置認證信息,在<servers>節點添加以下配置:shell
<server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server>
在pom.xml添加部署配置apache
<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設置代理倉庫
<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> <!-- 打包時跳過測試 --> <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中,已經沒有了能對maven私服進行deploy的默認用戶,只有admin和匿名用戶。爲了讓一個角色可以對maven進行deploy,須要向它添加匿名角色全部權限和以下幾個權限:
4.一、下載安裝包:https://github.com/goharbor/harbor/releases
4.二、上傳到 /usr/local/docker/目錄
4.三、解壓 tar -zxvf harbor-offline-installer-v1.9.1-rc1.tgz
4.四、進入到harbor目錄修改harbor.yml文件
hostname: 192.168.100.102 http: port: 8090 harbor_admin_password: Harbor12345
4.五、執行 install.sh
啓動後訪問:http://192.168.100.101:8090 用戶名:admin 密碼:Harbor12345
4.六、配置客戶端
##沒有此文件就建立 vim /etc/docker/daemon.json { "registry-mirrors":[ "https://registry.docker-cn.com" ], "insecure-registries":[ "192.168.100.101:8090" ] } 注意:該文件必須符合JSON規範,不然docker將不能啓動
4.七、重啓服務
systemctl daemon-reload systemctl restart docker
4.八、檢查私服配置
docker info
4.9 、製做鏡像提交到harbor倉庫
##拉取nginx docker pull nginx ## 在項目中標記鏡像 ## 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 ## 推送鏡像到當前項目 ## docker push 192.168.100.101:8090/itchao-saas/IMAGE[:TAG] docker push 192.168.100.101:8090/itchao-saas/nginx:latest
預先建立一個網絡
##建立網絡 docker network create <Network Name> ##查看已存在的網絡 docker network list
在docker-compose.yml中指定網絡
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