docker-ubuntu

Source

docker ps

docker images

拉取ubuntu镜像

docker pull ubuntu

启动

docker start podid

docker run -itd -e TZ=Asia/Shanghai --name ubuntu-test -v /share:/shared -d ubuntu:latest

进入bash界面

docker exec -it podid /bin/bash

安装sudo

apt-get install sudo

更新使配置生效

sudo apt update

安装vim

apt-get install vim

安装中文包

sudo apt-get install language-pack-zh-hans
vim /etc/environment
追加:
LANG=“zh_CN.UTF-8”
LANGUAGE=“zh_CN:zh:en_US:en”

追加:vim /var/lib/locales/supported.d/local
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
zh_CN.GBK GBK
zh_CN GB2312

sudo locale-gen
sudo apt-get install fonts-droid-fallback ttf-wqy-zenhei ttf-wqy-microhei fonts-arphic-ukai fonts-arphic-uming

安装python

sudo apt-get install software-properties-common python-software-properties
sudo apt-get install python3.6
sudo apt-get update

安装pips

sudo apt install python3-pip
pip3 install --upgrade pip
pip -V

修改源:

sudo gedit /etc/apt/sources.list

卸载:

sudo apt-get remove --auto-remove python3.8
sudo apt-get purge --auto-remove python3.8
sudo apt-get autoclea python3.8

安装mysql

sudo apt install mysql-server
mysql --version

查看服务状态

service mysql status

启动mysql服务

service mysql start

停止mysql服务

service mysql stop

重启mysql服务

service mysql restart

修改mysql配置文件

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

bind-address = 127.0.0.1

mysql -uroot -p root
mysql->use mysql
mysql->update user set host = ‘%’ where user =‘root’;
mysql->grant all privileges on . to ‘root’@‘%’ with grant option;
mysql->flush privileges;
mysql->exit;
sudo /etc/init.d/mysql restart

查ip:

sudo apt install net-tools
ifconfig

vim中文乱码问题

  1. vim ~/.vimrc

    输入:
    set fileencodings=utf-8,gb2312,gbk,gb18030
    set termencoding=utf-8
    set fileformats=unix
    set encoding=prc

  2. python代码中加入:

    import sys
    import codecs

    sys.stdout = codecs.getwriter(“utf-8”)(sys.stdout.detach())

shell脚本编写

  1. vim shell.sh

​ 第一行 :#!/bin/bash

​ 执行逻辑:python run.py

  1. 保存文件

  2. 修改文件为执行权限

​ chmod +x ./shell.sh

  1. 开始执行shell脚本 ./shell.sh

定时任务

编辑定时任务
crontab -e
查看定时任务
crontab -l
重启定时任务
service cron restart





启用ubuntu系统ssh链接

su -
sudo apt-get install openssh-server
sudo ps -e | grep ssh
sudo service ssh start
sudo systemctl enable --now ssh
sudo apt-get install net-tools

软连接python

sudo apt-get update
sudo apt-get install software-properties-common


sudo apt-get update
sudo apt-get install python-is-python3
sudo apt-get install python3-pip

ubuntu安装docker

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  
  sudo apt-get update
  
  sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  

docker 搭建私有镜像库,上传下载镜像

docker run --name registry -d  -p 5000:5000 --restart=always  -v /opt/data/registry:/var/lib/registry registry

docker run -itd --name ubuntu-dev --restart=always -v E:\share:/home/share ubuntu:latest
# 将正在运行的容器打包成镜像
docker commit ubuntu:latest 192.168.2.108:5000/ubuntu:latest

docker tag ubuntu:latest 192.168.2.108:5000/ubuntu:latest

vim /etc/docker/daemon.json
{
  "insecure-registries": ["192.168.2.108:5000"]
}
sudo systemctl restart docker


docker push 192.168.2.108:5000/ubuntu:latest

docker pull 192.168.2.108:5000/ubuntu:latest