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 小时前
win11 分屏设置
java·开发语言·驱动开发·docker·单例模式·计算机外设
小天源2 小时前
CentOS 7介绍及其下载
linux·运维·ubuntu·centos·麒麟·windows11·windows10
岳来2 小时前
网络小白理解容器网络endpointid
网络·docker·endpoint
十年编程老舅2 小时前
冲刺米哈游|游戏开发一面面经(26 届
linux·c++·米哈游
CHU7290352 小时前
一番赏盲盒抽卡机小程序:解锁惊喜体验与社交乐趣的多元功能设计
前端·小程序·php
RFCEO2 小时前
前端编程 课程十二、:CSS 基础应用 Flex 布局
前端·css·flex 布局·css3原生自带的布局模块·flexible box·弹性盒布局·垂直居中困难
闫记康2 小时前
linux配置ssh
linux·运维·服务器·学习·ssh
2401_859049082 小时前
lvgl移植到Linux踩坑
linux·运维·arm开发·elasticsearch·嵌入式·ubantu
CheungChunChiu2 小时前
V4L2 框架下 `v4l2-ctl --list-frameintervals` 调用链解析
linux·ubuntu·sensor·cam