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
相关推荐
C_心欲无痕15 小时前
ts - tsconfig.json配置讲解
linux·前端·ubuntu·typescript·json
HIT_Weston17 小时前
93、【Ubuntu】【Hugo】搭建私人博客:面包屑(一)
linux·运维·ubuntu
唯情于酒17 小时前
Docker学习
学习·docker·容器
喵叔哟17 小时前
20.部署与运维
运维·docker·容器·.net
HIT_Weston17 小时前
92、【Ubuntu】【Hugo】搭建私人博客:侧边导航栏(六)
linux·运维·ubuntu
CodeAllen嵌入式17 小时前
Windows 11 本地安装 WSL 支持 Ubuntu 24.04 完整指南
linux·运维·ubuntu
德育处主任20 小时前
『NAS』在群晖部署一个文件加密工具-hat.sh
前端·算法·docker
老前端的功夫21 小时前
TypeScript 类型魔术:模板字面量类型的深层解密与工程实践
前端·javascript·ubuntu·架构·typescript·前端框架
HABuo1 天前
【Linux进程(四)】进程切换&环境变量深入剖析
linux·运维·服务器·c语言·c++·ubuntu·centos