Docker-构建自己的Web-Linux系统-Ubuntu:22.04

Dockerfile.V1

bash 复制代码
# Dockerfile
FROM ubuntu:22.04

# 避免交互式安装
ENV DEBIAN_FRONTEND=noninteractive

RUN cp /etc/apt/sources.list /etc/apt/sources.list.backup && \
    cat > /etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ jammy universe
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates universe
deb http://mirrors.aliyun.com/ubuntu/ jammy multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ jammy-security universe
deb http://mirrors.aliyun.com/ubuntu/ jammy-security multiverse
EOF


# 更新软件包并安装SSH服务
RUN apt-get update && \
    apt-get install -y openssh-server sudo && \
    mkdir /var/run/sshd && \
    echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && \
    echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config && \
    echo 'root:root' | chpasswd && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 暴露所有需要的端口
EXPOSE 22

# 启动SSH服务并运行init
CMD ["/sbin/init"]

包含aliyun源

包含sshd服务

构建镜像

bash 复制代码
docker build -t ubuntu-ssh:22.04 -f Dockerfile.V1 .

日志

bash 复制代码
=> exporting to image                                                                                                                                                                                                       0.0s
 => => exporting layers                                                                                                                                                                                                      0.0s
 => => writing image sha256:fe4ef1b8b9c1b74c16b077e032ae49f815813ce20f363f79aedd9c5b24d42b4f                                                                                                                                 0.0s
 => => naming to docker.io/library/ubuntu-ssh:22.04

docker images

bash 复制代码
(base) [root@ai-server ubuntu]# docker images
REPOSITORY                                            TAG                        IMAGE ID       CREATED          SIZE
ubuntu-ssh                                            22.04                      fe4ef1b8b9c1   1 minutes ago   190MB

创建容器

bash 复制代码
docker run -d \
  --name ssh_v1 \
  -p 28521:22 \
  --privileged \
  --restart unless-stopped \
  ubuntu-ssh:22.04

端口28521可自己调整

主机开发端口(我的是CentOS)

bash 复制代码
iptables -A INPUT -p tcp --dport 28521 -j ACCEPT

可以通过28521访问了

用户名/密码 root/root

相关推荐
子兮曰2 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
子兮曰2 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
未济2 天前
linux 配置环境变量
linux
傲世仙尊2 天前
目录即文件-Ext文件系统收尾篇
linux·c语言
前端小万2 天前
写公众号赚了 3000 块后,我做了一款叫 "一键成稿" 的软件
前端·微信小程序
爱勇宝2 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
三十而立洋2 天前
Cookie 详解:从产生到安全,一次讲透
前端·javascript
分布式存储与RustFS2 天前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
卡布鲁2 天前
把一个 Vite + Vue3 应用塞进 qiankun (React + Umi3) 主站:十个坑的复盘
前端·javascript·react.js
_艾伦 耶格尔.2 天前
进程间通信
linux