avatar

松果工作室

欢迎光临

  • 首页
  • ESP
  • LVGL
  • freeRTOS
  • 快速笔记
  • 考察日志
  • 个人收藏
  • 我的服务
Home (Linux)Docker 安装 Ubuntu 环境
文章

(Linux)Docker 安装 Ubuntu 环境

Posted 2024-01-6 Updated 2024-03- 24
By YCP
7~9 min read

安装 Docker For Desktop

获取镜像

docker --version
docker-compose --version
docker pull ubuntu:20.04  # 获取 ubuntu 镜像
docker image ls  # 查看当前安装的Docker镜像

创建容器

docker run -i -t --name ubuntu_cc ubuntu bash  # 创建并运行一个可以使用终端交互的 ubuntu 容器,命名为 ubuntu_cc
cat /etc/issue  # 查看ubuntu系统版本
control d  # 退出容器

启动容器

docker ps -a  # 列出所有容器信息,包括已经关闭的。
docker start -i ubuntuTest  # -i启动容器,可以进入终端交互。

容器内自行配置

apt update
apt-get install nano  # 安装 nano
apt-get install git python3  # 安装 git 和 python3
apt-get install openssh-server  # 安装 openssh-server,用于开启 ssh 服务供外部连接。
# 安装中途选择的 6-Asia   70-shanghai

vim /etc/ssh/sshd_config  
# 更改 sshd 的默认配置 去掉下面3处的注释符#
#34行,PermitRootLogin prohibit-password 只允许使用公钥身份验证(禁止使用密码登录)
#39行,PubkeyAuthentication yes 启用公钥身份验证
#42行,AuthorizedKeysFile      .ssh/authorized_keys .ssh/authorized_keys2
#告诉 SSH 服务器在这些文件中寻找授权的公钥,用于用户进行身份验证。

/etc/init.d/ssh restart  # 重启sshd
mkdir ~/.ssh
touch ~/.ssh/authorized_keys
# 在本机mac终端,cat ~/.ssh/id_rsa.pub  如果没有该文件,终端输入ssh-keygen,连续回车enter,即生成该文件;
# 将本机id_rsa.pub的一行内容,nano复制到docker容器的 ~/.ssh/authorized_keys中

control d  # 退出容器

打包镜像

docker ps -a
#找出容器 ID
docker commit -m 'add ssh' -a 'ycp666' d4b0fc9b1e81 ubuntu-ssh
# -m,指定提交信息; -a,指定提交者; 容器 ID; ubuntu-ssh 是新镜像的名称

docker rm ubuntu_cc

docker run -d -p 22222:22 --name ubuntu_cc ubuntu-ssh /usr/sbin/sshd -D
# -d 后台运行; -p 绑定宿主机的22222端口到ubuntu容器的22端口; --name 给容器取名为ubuntuTest; 
# ubuntu-ssh 使用镜像ubuntu-ssh创建容器; /usr/sbin/sshd -D 指定容器启动使用的应用及参数;
ssh -p 22222 root@localhost  # 不输密码,直接进入容器ubuntu_cc;

# 在本机 macOS,vim ~/.ssh/config,添加如下内容:
Host ubuntuTest
    HostName localhost
    User     root
    Port     22222
# 然后可以 ssh ubuntuTest 连接容器
坑和笔记
Linux
License:  CC BY 4.0
Share

Further Reading

Sep 27, 2025

(LIB)一个好用的Modbus解析函数

一个好用的Modbus解析函数 包含03/10/04/06 #include <stdio.h> #include <stdint.h> #include <string.h> #

Jun 21, 2024

(LIB)环形滤波算法

#include <stdio.h> #include <stdlib.h> #define BUFFER_SIZE 10 // 缓冲区大小 #define THRESHOLD 180

Jun 17, 2024

(STM32)STM32 ADC采集的三种方式

采样周期 单个采集模式 ADC_Settings: 程序使用 uint16_t ADC_Read(

OLDER

(LIB)软件I2C

NEWER

(LIB)步进电机篇

Recently Updated

  • (ESP-IDF)LVGL 模拟器
  • (ESP-IDF)LVGL 自定义对象加入编码器组
  • (ESP-IDF)vscode配置文件
  • (Elec)来复再生式晶体管单管收音机
  • (ESP-IDF)ESPNOW

Trending Tags

LVGL WCH Linux Elec ThatProject freeRTOS STM ESP Flutter Others

Contents

©2026 松果工作室. Some rights reserved.

Using the Halo theme Chirpy