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

相关推荐
古译汉书3 分钟前
串口模拟工具:com0com 介绍、下载、驱动感叹号解决
linux·运维·服务器·stm32·单片机·嵌入式硬件
程序员林北北10 分钟前
【前端进阶之旅】Svelte:编译即框架,让前端开发回归简洁
前端·javascript·vue.js·react.js·html5
Trouvaille ~16 分钟前
【Linux】epoll 深度剖析:高性能 IO 多路复用的终极方案
linux·运维·服务器·c++·epoll·多路复用·io模型
yy.y--39 分钟前
Java线程实现浏览器实时时钟
java·linux·开发语言·前端·python
Dontla44 分钟前
Python Streamlit介绍(开源Python Web应用框架,快速将Python脚本转换成交互式Web应用,适合数据科学和机器学习项目快速展示)
前端·python·开源
暴力求解1 小时前
Linux---进程(九)进程控制
linux·运维·服务器
少云清1 小时前
【UI自动化测试】12_web自动化测试 _验证码处理和cookie
前端·python·web自动化测试
礼拜天没时间.1 小时前
企业级Docker镜像仓库Harbor部署实战
linux·运维·docker·云原生·容器·sre
晚风_END1 小时前
Linux|操作系统|小技巧---vim编辑的脚本自动添加shebang 和注释
linux·运维·vim
能源革命2 小时前
Ubuntu24.04修改ssh默认端口
linux·服务器·ssh