docker install

docker install install docker on Debian/Ubuntu link Uninstall old versions $ sudo apt-get remove docker docker-engine docker.io containerd runc Set up the repository $ sudo apt-get update $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common $ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - or $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - $ sudo apt-key fingerprint 0EBFCD88 $ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/debian \ $(lsb_release -cs) \ stable" or sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ focal \ stable" or $ sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \ $(lsb_release -cs) \ stable" Install Docker Engine $ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io $ sudo docker run --rm hello-world $ sudo apt install docker-compose -y Without sudo to use docker $ sudo usermod -aG docker $USER $ sudo systemctl restart docker $ sudo systemctl enable docker Speed up https://YOURS.mirror.aliyuncs.com ...

April 20, 2020 · 1 min · Peter

Toolbox

Tool Hub 各个分类的工具汇总 开发 代码 nvim vscode jetbrains vim 代码管理 gitea gitlab CI drone jetbrains teamcity gitlab 接口测试 postman httpie jebrains http test curl 接口mock测试 httpretty: a full fake TCP socket module. Inspired by FakeWeb(ruby), 用于模拟http外部访问请求 responses: A utility for mocking out the Python Requests library. 接口性能测试 vegeta pssh + vegeta, pssh并行在多个计算机中执行命令,vegeta接口性能测试工具,支持代码修改、命令模式,输出json、text、gob、html等格式 apache benchmark(ab) 代码性能分析 Python memray pytest-memray py-spy, Never use print for debugging again PySnooper, Never use print for debugging again 文档 markdown: ...

March 17, 2020 · 1 min · Peter

vue cors

利用proxy 解决 Django Vue 开发环境中的跨域问题 最近使用 Django+Vue的组合快速的做一个项目,前段之前有看过,但是只是👀会了,这次实际操作,在前后端分离后的开发环境中踩了坑。 环境 Django + DRF Django Channels,主要是websocket vue-admin-template,一个开源的项目,很多东西都有实现,新手可以用来改改就用,还能学习 开发环境: wsgi, 8000 asgi, 8001 vue, 9528 问题 想像在使用nginx一样的透明的使用开发环境 django已经配置了corsheaders middleware了 尝试 axios显示指定地址和端口到8000的服务上,解决了axios实例的访问,但是使用 el-upload的表单时,发现就不好使了,localhost和其他不同域,拿不到 cookie中的csrftoken,导致被 django拒绝 解决 在查看了各种文档后,最有效的方案是devServer的proxy,这是webpack提供的功能,使用的是http-proxy-middleware这个中间件,文档很详细,可以看看。 目标: 代理 /api的请求到8000端口的wsgi server 代理 /ws的请求到8001的asgi server /api ---> localhost:8000/api localhost:9528 (cookie) -- /ws ---> localhost:8001/ws vue.conf.js devServer: { ... proxy: { [process.env.VUE_APP_BASE_API]: { target: 'http://127.0.0.1:8000', changeOrigin: true, ws: false, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }, cookieDomainRewrite: { '*': 'localhost' } }, '/ws': { target: 'ws://127.0.0.1:8001', // changeOrigin: true, secure: false, ws: true } } ... } 说明: ...

March 17, 2020 · 1 min · Peter

Vagrant

如何使用 Vagrant 快速搭建环境 加速 可以直接从国内镜像下载 box格式的文件,然后用 vagrant box add NAME URL添加 # 自己下载 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/focal/current/ 制作自己的box 官方文档 正常安装镜像,然后安装基础环境 导出 vagrant package --base ubuntu20.04 --output ./ubuntu2004.box 添加box vagrant box add ubuntu2004 .\ubuntu2004.box 如果没有Vagrantfile,则初始化 vagrant box add ubuntu2004 .\ubuntu2004.box 启动 vagrant up VagrantFile # -*- mode: ruby -*- # vi: set ft=ruby : servers = { :k3s1 => '192.168.1.21', :k3s2 => '192.168.1.22', :k3s3 => '192.168.1.23' } Vagrant.configure("2") do |config| # 可以指定自己导出的box config.vm.box = "ubuntu/focal64" servers.each do |server_name, server_ip| config.vm.define server_name do |server_config| server_config.vm.hostname = "#{server_name.to_s}" server_config.vm.network :private_network, ip: server_ip server_config.vm.provider "virtualbox" do |vb| vb.name = server_name.to_s vb.memory = 1024 vb.cpus = 1 end end end end

May 6, 2019 · 1 min · Peter

docker env file

docker env file 在docker-compose 中使用以下方式导入.envfile。 web: build: . restart: always working_dir: /deploy/mysite command: ./service_web.sh env_file: - .env # environments .env DOCKER=1 HOME=/deploy 想用shell script动态获取环境的CPU count 如果直接在.env 中写如下的内容,会报语法错误: CPU_NUM=$(cat /proc/cpuinfo |grep processor|wc -l) 所以,在web服务的command: ./service_web.sh脚本中export一个变量,并在gunicorn中使用: #!/bin/bash sleep 5 export CPU_NUM=$(cat /proc/cpuinfo |grep processor|wc -l) python manage.py collectstatic -v0 --noinput python manage.py migrate --noinput /usr/local/bin/gunicorn -w $((2*$CPU_NUM+1)) -b unix:/deploy/running/handle/django-tutorial-server.sock mysite.wsgi:application --log-level info

January 1, 2019 · 1 min · Peter