Last updated on 2 months ago
20221204 装机笔记
安装Docker
1 2 3 4 5 6
| sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
|
1
| curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
|
1
| sudo apt-key fingerprint 0EBFCD88
|
1 2 3 4
| sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \ $(lsb_release -cs) \ stable"
|
1
| sudo apt-get install docker-ce docker-ce-cli containerd.io
|
1
| sudo docker run hello-world
|
1
| systemctl enable docker.service
|
安装Docker-compose
1
| curl -L "https://gitee.com/large_cat/docker-compose/raw/main/install.sh" | sh
|
1
| chmod +x /usr/local/bin/docker-compose
|
build
1
| docker build -t resume:1.0.0.1 .
|
run
1
| docker run -p 5000:5000 -d resume:1.0.0.1 --name resumev1001
|
环境
没啥用
1
| sudo snap install dotnet-sdk --classic --channel=6.0
|
1
| sudo snap alias dotnet-sdk.dotnet dotnet60
|
1
| sudo snap install dotnet-runtime-60
|
1
| sudo snap alias dotnet-runtime-60.dotnet dotnet
|
1
| export DOTNET_ROOT=/snap/dotnet-sdk/current
|
1
| export SSL_CERT_FILE=[path-to-certificate-file]
|
1
| export SSL_CERT_DIR=/dev/null
|
1
| ln -s /snap/dotnet-sdk/current/dotnet /usr/local/bin/dotnet
|
linux
运行 dotnet6
下载
1
| sudo wget https://download.visualstudio.microsoft.com/download/pr/cd0d0a4d-2a6a-4d0d-b42e-dfd3b880e222/008a93f83aba6d1acf75ded3d2cfba24/dotnet-sdk-6.0.400-linux-x64.tar.gz
|
1
| sudo tar zxvf dotnet-sdk-6.0.400-linux-x64.tar.gz -C dotnet
|
配置环境变量
1 2 3 4 5 6
| sudo vim /etc/profile
//在文件尾部添加 export PATH=$PATH:/data/dotnet export DOTNET_ROOT=/data/dotnet //注:/data/dotnet是我的存储路径,这里改成你自己的路径
|
重启网路服务指令
快捷操作
1 2 3 4 5 6 7
| docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
curl -X 'GET' \ 'http: -H 'accept: text/plain'
|
ubuntu
开启/关闭防火墙
1 2 3 4 5
| 1、Alt+T打开终端,输入sudo ufw status回车,查看防火墙状态,inactive是关闭,active是开启。
2、使用sudo ufw enable开启防火墙。
3、使用sudo ufw disable关闭防火墙。
|
Dockerfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 5000
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY . .
ENV ASPNETCORE_URLS=http://+:5000
# ENTRYPOINT ["dotnet", "XLZF.ClothingManage.dll"]
ENTRYPOINT ["dotnet"]
CMD ["Resume.DataBase.dll"]
|
Docker-compose
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| version: "3.0" services: resumedatabase: build: context: ./ dockerfile: Dockerfile ports: - 5000:5000 networks: - my-network restart: always
networks: my-network: external: name: mynet
|
1
| docker-compose up -d --build
|
Docker Portainer.io
图形化配置docker-compose
Docker for Vue
1 2 3 4 5 6 7 8 9 10 11
| 1. docker pull nginx 2. docker run --name=nginx -d -p 4030:80 nginx 3. 添加Dockerfile # 设置基础镜像,这里使用最新的nginx镜像,前面已经拉取过了 FROM nginx # 定义作者 MAINTAINER Harris # 将dist文件中的内容复制到 /usr/share/nginx/html/ 这个目录下面 COPY /dist/ /usr/share/nginx/html/ 4. docker build -t dockervue . 5. docker run --name=dockervue -d -p 7681:80 dockervue
|
.net 6.0服务+vue docker-compose
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| version: "3.0" services: resumedatabase: container_name: resumedatabase build: context: ./database/1001/ dockerfile: Dockerfile ports: - 5000:5000 networks: - my-network restart: always resumesystem: container_name: resumesystem build: context: ./system/1001/ dockerfile: Dockerfile ports: - 5001:5000 networks: - my-network restart: always resumevue: container_name: resumevue build: context: ./vue/ dockerfile: Dockerfile ports: - 6666:80 networks: - my-network restart: always
networks: my-network: external: name: mynet
|
执行
结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| root@instance-dgf6qfwk:/netcore/resume# docker-compose up -d --build Building resumedatabase Step 1/9 : FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base ---> 846be731181b Step 2/9 : WORKDIR /app ---> Using cache ---> 24d99f83aca9 Step 3/9 : EXPOSE 5000 ---> Using cache ---> 67e35cd2b60c Step 4/9 : FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build ---> 55e890ae9ccb Step 5/9 : WORKDIR /src ---> Using cache ---> 784fa469cc01 Step 6/9 : COPY . . ---> Using cache ---> 45678be9eac6 Step 7/9 : ENV ASPNETCORE_URLS=http://+:5000 ---> Using cache ---> fcdc676d4bac Step 8/9 : ENTRYPOINT ["dotnet"] ---> Using cache ---> 9063f5dcc256 Step 9/9 : CMD ["Resume.DataBase.dll"] ---> Using cache ---> 6c06c1ebc98d Successfully built 6c06c1ebc98d Successfully tagged resume_resumedatabase:latest Building resumesystem Step 1/9 : FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base ---> 846be731181b Step 2/9 : WORKDIR /app ---> Using cache ---> 24d99f83aca9 Step 3/9 : EXPOSE 5000 ---> Using cache ---> 67e35cd2b60c Step 4/9 : FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build ---> 55e890ae9ccb Step 5/9 : WORKDIR /src ---> Using cache ---> 784fa469cc01 Step 6/9 : COPY . . ---> Using cache ---> 5a131cdf9d7c Step 7/9 : ENV ASPNETCORE_URLS=http://+:5000 ---> Using cache ---> 7115dd76d339 Step 8/9 : ENTRYPOINT ["dotnet"] ---> Using cache ---> d9fcf4d6a8bb Step 9/9 : CMD ["Resume.System.dll"] ---> Using cache ---> ed79d892ccef Successfully built ed79d892ccef Successfully tagged resume_resumesystem:latest Building resumevue Step 1/3 : FROM nginx ---> 88736fe82739 Step 2/3 : MAINTAINER Harris ---> Using cache ---> 437cf52b5c5d Step 3/3 : COPY /dist/ /usr/share/nginx/html/ ---> Using cache ---> eff9caddd35d Successfully built eff9caddd35d Successfully tagged resume_resumevue:latest Creating resumedatabase ... done Creating resumevue ... done Creating resumesystem ... done root@instance-dgf6qfwk:/netcore/resume# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bf074243b66a resume_resumesystem "dotnet Resume.Syste…" 8 seconds ago Up 5 seconds 0.0.0.0:5001->5000/tcp, :::5001->5000/tcp resumesystem 5c48eaa90d29 resume_resumevue "/docker-entrypoint.…" 8 seconds ago Up 5 seconds 0.0.0.0:5002->80/tcp, :::5002->80/tcp resumevue e010e4558f08 resume_resumedatabase "dotnet Resume.DataB…" 8 seconds ago Up 6 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp resumedatabase
|
文件目录:
1 2 3 4 5 6 7 8 9 10 11 12 13
| |--netcore |--netcore/resume |--netcore/resume/docker-compose.yml (重要) |--netcore/resume/database |--netcore/resume/database/1001/ |--netcore/resume/database/1001/{database发布文件} |--netcore/resume/system |--netcore/resume/system/1001/ |--netcore/resume/system/1001/{system发布文件} |--netcore/resume/vue |--netcore/resume/vue/dist/ |--netcore/resume/vue/dist/{vue发布文件} |--netcore/resume/vue/Dockerfile
|
Mysql
这里主要是pull 5.7版本,高版本修改密码有问题
这个映射不好使,问题后面在看
1
| docker run -p 3306:3306 --name mysql -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
|
这个好使
1
| docker run -p 3306:3306 --name mysql -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
|
Jenkins
第一种
docker-compose.yml
1 2 3 4 5 6 7 8 9 10
| version: "3.1" services: jenkins: image: jenkins/jenkins:2.332.3-lts container_name: jenkins ports: - 9999:8080 - 50000:50000 volumes: - /root/jenkins/data/:/var/jenkins_home/
|
如有有报错就是权限的事
1 2 3
| root@jenkins:~/jenkins# docker logs jenkins touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
|
解决:给映射的data文件夹赋权限
也可以参考
1 2 3 4 5 6 7
| docker run -u root --rm -d -p 3000:8080 \ --name jenkins \ -v /etc/localtime:/etc/localtime \ -v /usr/bin/docker:/usr/bin/docker \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /home/dockerVolumes2/jenkins_home:/var/jenkins_home \ registry.cn-hangzhou.aliyuncs.com/bcvp/jenkins_with_dntcore3.1_5.0_6.0-cnpm_by_docker:latest
|
第二种
Jenkins自动化构建.Net6项目 - 墨天轮 (modb.pro)
pull
1
| docker pull jenkins/jenkins
|
创建映射文件夹并且赋权限
1 2 3 4 5 6 7 8 9 10 11 12 13
| mkdir -p /var/docker_data/jenkins/jenkins_home
mkdir -p /var/docker_data/jenkins/settings
mkdir -p /var/docker_data/jenkins/root
chmod 777 /var/docker_data/jenkins/jenkins_home
chmod 777 /var/docker_data/jenkins/settings
chmod 777 /var/docker_data/jenkins/root
chmod -R 777 /var/docker_data/jenkins
|
启动
1
| sudo docker run --name usJenkins --user=$UID:$(id -g $USER) -d -p 10240:8080 -p 10241:50000 -v /etc/localtime:/etc/localtime -v /var/docker_data/jenkins/jenkins_home:/var/jenkins_home -v /var/docker_data/jenkins/root:/root -v /var/docker_data/jenkins/settings:/var/settings -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker --privileged=true --restart=always jenkins/jenkins
|
Jenkins 配置 gitee秘钥
Jenkins凭据管理—-配置Gitee私钥_redrose2100的博客-CSDN博客_jenkins配置git密钥
Docker for Gitlab
第一种
1
| docker pull gitlab/gitlab-ce:latest
|
1 2 3 4 5 6
| mkdir -p /opt/docker/gitlab
cd /opt/docker/gitlab
vim docker-compose.yml
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| version: '3.6' services: web: image: 'gitlab/gitlab-ee:latest' restart: always container_name: 'gitlab' hostname: 'gitlab' environment: GITLAB_OMNIBUS_CONFIG: | external_url 'http://192.168.31.95:8929' gitlab_rails['gitlab_shell_ssh_port'] = 2224 ports: - '8929:8929' - '2224:22' volumes: - '$GITLAB_HOME/config:/etc/gitlab' - '$GITLAB_HOME/logs:/var/log/gitlab' - '$GITLAB_HOME/data:/var/opt/gitlab' shm_size: '256m
|
注意,其中的external_url后面的ip地址需要修改为自己服务器的内网ip,完成后保存退出。
1 2 3
| # 将下面的地址改成你存放gitlab持久化数据的地址,比如我的地址为/opt/docker/gitlab export GITLAB_HOME=/opt/docker/gitlab docker-compose up -d
|
放行8929和2224两个端口。
1 2
| firewall-cmd --add-port={8929,2224}/tcp --permanent firewall-cmd --reload
|
使用以下命令查看一下初始密码:
1
| docker exec -it gitlab cat /etc/gitlab/initial_root_password
|
登录 root - 刚查看的密码
第二种
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| ```
```dockerfile version: "3" services: gitlab: image: gitlab/gitlab-ce:13.1.2-ce.0 container_name: 'devops-gitlab' restart: always hostname: '<your hostname>' environment: GITLAB_OMNIBUS_CONFIG: | external_url "<your gitlab url>" gitlab_rails['gitlab_shell_ssh_port'] = 23 gitlab_rails['time_zone'] = 'Asia/Shanghai' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.exmail.qq.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "<your qq email>" gitlab_rails['smtp_password'] = "xCcqh*L4jkqFCS" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true gitlab_rails['gitlab_email_from'] = '<your qq email>' gitlab_rails['smtp_domain'] = "exmail.qq.com" ports: - '81:80' - '443:443' - '23:22' volumes: - '/gitlab/config:/etc/gitlab' - '/gitlab/logs:/var/log/gitlab' - '/gitlab/data:/var/opt/gitlab' logging: driver: "json-file" options: max-size: "20m" max-file: "10"
|