ubuntu 22.04安装和使用docker介绍

docker安装和使用

准备环境

本机环境:

bash 复制代码
Linux yz-MS-7E06 6.8.0-59-generic #61~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 15 17:03:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

安装依赖软件:

bash 复制代码
sudo apt install apt-transport-https ca-certificates curl software-properties-common

添加官方的GPG秘钥:

bash 复制代码
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

添加官方的仓库:

bash 复制代码
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update

安装docker软件:

bash 复制代码
sudo apt install docker-ce docker-ce-cli containerd.io
$ sudo docker --version
Docker version 28.1.1, build 4eba377

配置非 root 用户使用 Docker:

bash 复制代码
sudo usermod -aG docker $USER
newgrp docker

安装Docker Desktop软件,在如下链接下载: 官网,如下是安装教程:

bash 复制代码
 sudo apt install gnome-terminal #安装GNOME
 sudo apt-get update
 sudo apt-get install ./docker-desktop-amd64.deb
 systemctl --user start docker-desktop #从用户启动
 systemctl --user stop docker-desktop #停止退出

常见的docker操作

第一次进行ubuntu22.04的系统测试,从华为云拉取镜像:

bash 复制代码
docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/ubuntu:22.04
docker tag  swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/ubuntu:22.04  docker.io/ubuntu:22.04
docker run -it --name myUbuntu ubuntu:22.04 bash

Docker Desktop软件可以看见如下:
通过命令查看镜像的情况:

bash 复制代码
docker images #查看本地存在的镜像文件
docker images ps -a #查看镜像文件(包括停止的容器)

从已经停止的镜像继续运行:

bash 复制代码
docker start -i myUbuntu

提交运行的镜像版本命令:

bash 复制代码
docker commit -m "Added new software packages" myUbuntu  release:v1.0

镜像文件的导出命令:

bash 复制代码
docker save -o ./back/ubuntu.tar release:v1.2

使用其它命令导入镜像文件

bash 复制代码
docker load -i ubuntu.tar

将本地的文件夹挂在到容器里面的操作:

bash 复制代码
docker run -it --name mountUbuntu  -v /home/yz/workFile/docker/file:/home/yz/file release:v1.2

比如有需求要进入已经启动的容器进入或者想要开两个命令窗口,执行如下命令:

bash 复制代码
docker exec -it mountUbuntu bash

上面的mountUbuntu名字根据docker ps -a进行查询如下图:

linux系统常用的配置

默认进入docker中是root用户,如下新增普通用户命令配置:

bash 复制代码
useradd -m myuser
passwd myuser
usermod -aG sudo myuser
su - myuser #切换到新的用户

新增的普通用户支持sudo权限

bash 复制代码
apt-get update && apt-get install sudo
usermod -aG sudo <username>

配置source命令:

bash 复制代码
echo $SHELL  # 确认当前 shell
#如果输出不是 /bin/bash,则可以通过以下命令更改 shell
chsh -s /bin/bash <username>

解决yocto编译的时候遇到的en_US.UTF-8问题:

bash 复制代码
apt-get install -y locales
locale-gen en_US.UTF-8
dpkg-reconfigure locales
locale #查看配置是否生效

新增自动补全命令:

bash 复制代码
apt install bash-completion
exec bash
#修改配置文件~/.bashrc,新增下面的配置
# enable bash completion in interactive shells
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi
source ~/.bashrc

安装网络软件:

bash 复制代码
apt update
apt install net-tools
apt install iputils-ping
apt install vim

卸载docker

要卸载 Docker,可以使用以下命令:

bash 复制代码
sudo apt remove docker-ce docker-ce-cli containerd.io
sudo apt purge docker-ce docker-ce-cli containerd.io
sudo apt autoremove --purge
相关推荐
Tronlong创龙9 小时前
SBC-TL3588 单板机 / EPC-TL3588 工控机 Docker 开发手册(二)
docker·开发板·嵌入式开发·硬件开发·工业控制
醉熏的石头14 小时前
Ubuntu 中的编程语言(中)
linux·ubuntu·scala
AI服务老曹14 小时前
视觉算法模型管理完整流程:多版本上线、灰度发布与回滚的落地实践
人工智能·docker·音视频
辉的技术笔记16 小时前
拆解 Dify 的 Celery:15 个队列都在干什么
docker
bukeyiwanshui19 小时前
20260622 安装配置ubuntu
linux·运维·ubuntu
AI的探索之旅1 天前
从 Ubuntu 14.04 到 24.04:TI AM335x 开发环境完整迁移与 Agent 接管方案
linux·数据库·嵌入式硬件·ubuntu·postgresql
渣渣盟1 天前
Docker 运维常用命令手册(含扩容与实战)
运维·docker·容器
小尘要自信1 天前
小米摄像头怎么接入RTSP?Go2RTC转流、EasyNVR录像与公网访问教程
人工智能·docker·开源
我叫张小白。1 天前
一个微服务电商+社区项目(瓷韵app)的技术深度复盘
docker·微服务·云原生·架构
一池秋_1 天前
ubuntu(linux)完美复刻windows11字体,解决linux字体费眼晴
linux·运维·ubuntu