linux 后台服务常用指令(包含部分docker常用命令)

netstat -a #查看端口占用情况

netstat -antup #可查看占用端口的进程,可用kill -9 结束进程

ps aux|grep python #只看python的相关进程,可用kill -9强制结束进程

ps -ef | grep python | grep -v grep | awk '{print $2}' | xargs kill -9 #结束所有有关python的进程

nohup python -u server.py > log.log 2>&1 & #后台运行程序,打印日志到log.log

docker ps #查看所有docker

docker attach docker_name #进入正在运行的名为docker_name的docker

docker images #查看所有镜像(image)

cat filename | tail -n 100 #抓取文件最后100行

docker logs -f --tail 100 docker_name #查看docker_name 最新100行日志

export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;  #可用于服务器FQ,目标IP必须能FQ

docker run --name video_similar -it -p 8005:8005 -v /Users/kpinfo/test/ThreatExchange/:/ThreatExchange image1:1.0 bash  #基于image1 1.0版本,创建名为video_similar的容器,端口映射-外部8005:容器内部8005,目录挂载:外部/Users/kpinfo/test/ThreatExchange/:容器内部/ThreatExchange

nvidia-docker run --name smart_media_video2text_middleware --restart=always -v /cmdata/:/cmdata/ -v /etc/localtime:/etc/localtime -e NVIDIA_VISIBLE_DEVICES=0 -d 192.168.132.136/ccwb/video2text_middleware:1.0  #gpu容器启动 (结尾 + /bin/bash -c "while true;do echo hello docker;sleep 1;done",容器运行后运行此段指令替换掉原镜像指令)

/etc/localtime:/etc/localtime  # docker启动替换本地时间

restart: always  # docker挂掉自启动

docker exec -it python env LANG=C.UTF-8 /bin/bash #进入名为python的容器(后台退出ctrl + alt + p)

docker commit -m "基于centos7的Pytho3.7镜像" centos7 centos7_python37:1.0 #基于明为centos7的容器制作名为centos7_python37的镜像 -m 提交内容随便写

docker save 新镜像id -o 要保存的tar包名称.tar  #将镜像打包为tar文件

docker load -i 镜像文件名.tar #加载tar文件为新镜像

docker rmi 镜像id #删除镜像

docker tag <image_id> 重新命名  #对镜像重新命名

git remote set-url origin #更换git仓库

mount 172.16.1.227:/cmdata      /cmdata  #共享目录,将172.16.1.227服务器的/cmdata目录,挂在到当前/cmdata目录

-i https://pypi.tuna.tsinghua.edu.cn/simple  #清华源

-i https://mirror.baidu.com/pypi/simple  #百度源

-i https://mirrors.aliyun.com/pypi/simple/ #阿里源

posted @ 2020-09-07 11:03  牛郎  阅读(253)  评论(0编辑  收藏  举报