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
相关推荐
不仙52012 小时前
VMware Workstation 26.0.0 在 Ubuntu 24.04 (内核 6.17.0) 上的安装与内核模块编译问题
linux·ubuntu·elasticsearch
dapeng-大鹏12 小时前
KVM+LVM 零停机在线扩容 Ubuntu 根分区:从磁盘添加到逻辑卷扩展完整
linux·运维·ubuntu·磁盘空间扩展
仙柒41513 小时前
Docker存储原理
运维·docker·容器
快乐的哈士奇16 小时前
LangFuse 自托管实战:选型理由、Docker 部署与常用配置全解析
运维·人工智能·docker·容器
weixin_4492900117 小时前
Docker + MySQL 在 Windows 11 上的本地安装部署文档
mysql·docker·容器
小小菜鸟,可笑可笑17 小时前
Ubuntu 系统安装搜狗输入法 & 使用英文标点
ubuntu
Ysn071917 小时前
中文乱码:在 Docker 容器中设置中文语言环境
运维·python·docker·容器
zxd02031118 小时前
EFK(Elasticsearch + Fluentd + Kibana) 日志收集系统
运维·docker·jenkins
终端行者18 小时前
Jenkins Pipeline 企业级用法 参数化构建+Ansible发布---上
docker·ansible·jenkins·cicd
亚空间仓鼠19 小时前
Docker容器化高可用架构部署方案(十三)
docker·容器·架构