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

相关推荐
螺蛳粉 螺蛳粉5 分钟前
第 03 篇:为什么 K8s 的最小调度单元是 Pod 而不是容器:pause 容器与边车模式(底座认知 03)
docker·云原生·容器·kubernetes·etcd·运维排障·kube-apiserver
l1m0_20 分钟前
AI设计工具有哪些?Paico、Pixso AI、墨刀AI、Lovable、Codex怎么选
前端·人工智能·ai·设计·墨刀·codex·pixso
web打印社区22 分钟前
Lodop在Edge和双核浏览器-先分清内核
前端·javascript·edge·pdf·ecmascript·html5
西瓜拿铁好喝27 分钟前
开源和闭源 AI 办公工具,分别适合谁
java·前端·数据库
IT_陈寒27 分钟前
深入理解SpringBoot:核心原理与最佳实践
前端·人工智能·后端
一技安身28 分钟前
MySQL 8.4.13 LTS 通用二进制包(Linux免安装版)完整教程
linux·mysql·adb
迷途之人不知返32 分钟前
【动态库与静态库】-3-静态链接与加载
linux
风骏时光牛马1 小时前
大模型综合能力多维评测:性能、逻辑与落地表现对比
前端
谙弆悕博士1 小时前
debian快速换源
linux·运维·windows·debian·下载·换源·网络问题
liuchangng1 小时前
React 19 + Vite 6 实战:从教材 PDF 到 866 词间隔重复单词 App
前端·react.js·pdf·vite·开源项目