DevOps
docker
docker
  • 基础知识
    • 概述
      • 核心概念
      • Docker 引擎
      • 基本架构
      • 联合文件系统
      • 网络虚拟化
    • 安装
      • 安装Docker Engine
      • 以非 root 用户使用 Docker
      • 配置 Docker 服务
    • 3. Docker镜像
      • 3.1 获取镜像(pull)
      • 3.2 查看镜像信息
        • images
        • tag
        • inspect
        • history
      • 3.3 搜寻镜像(search)
      • 3.4 删除镜像(rmi)
      • 3.5 清理镜像(prune)
      • 3.6 创建镜像
        • 基于已有容器创建
        • 基于本地模板导入
        • 基于Dockerfile创建
      • 3.7 导出镜像(save)
      • 3.8 导入镜像(load)
      • 3.9 上传镜像(push)
    • 4. Docker容器
      • 4.1 新建容器(create)
      • 4.2 启动容器(start)
      • 4.3 新建并启动容器(run)
      • 4.4 查看容器输出(logs)
      • 4.5 暂停容器(pause)
      • 4.6 恢复容器(unpause)
      • 4.7 停止止容器(stop)
      • 4.8 清除容器(prune)
      • 4.9 重启容器(restart)
      • 4.10 进入容器
      • 4.11 删除容器(rm)
      • 4.12 导出容器(export)
      • 4.13 导入容器(import)
      • 4.14 查看容器详情(inspect)
      • 4.15 查看容器内进程(top)
      • 4.16 查看统计信息(stats)
      • 4.17 复制文件(cp)
      • 4.18 查看变更(diff)
      • 4.19 更新配置(update)
    • 5. Docker仓库
      • 5.1 Docker Hub
      • 5.2 本地私有仓库
        • 使用HTTPS协议
        • 添加用户认证
        • 使用push时遇到的一些坑
    • 6. Docker数据管理
      • 6.1 数据卷
      • 6.2 数据卷容器
      • 6.3 利用数据卷容器来迁移数据
    • 7. 端口映射与容器互联
      • 7.1 端口映射
      • 7.2 容器互联
    • 8. Dockerfile
      • 8.1 基本结构
      • 8.2 指令说明
        • ARG
        • FROM
        • LABEL
        • EXPOSE
        • ENV
        • ENTRYPOINT
        • VOLUME
        • USER
        • WORKDIR
        • ONBUILD
        • STOPSIGNAL
        • HEALTHCHECK
        • SHELL
        • RUN
        • CMD
        • ADD
        • COPY
      • 8.3 创建镜像
      • 8.4 最佳实践
    • 9. Compose
      • 9.1 安装
      • 9.2 Compose文件
        • 9.2.1 services
        • 9.2.2 networks
        • 9.2.3 多文件Compose
          • Extend
          • Merge
          • Include
        • 9.2.4 锚点和别名
      • 9.3 Compose命令
      • 9.4 实例
  • 中间件安装
    • 安装tomcat
    • 安装redis
      • 单机
      • Cluster集群
    • 安装mysql
    • 安装ssh服务
      • 基于commit命令创建
      • 使用Dockerfile创建
    • 安装Apache
    • 安装ngnix
  • 操作系统镜像
    • BusyBox
    • ☑️Alpine
    • Debian/Ubuntu
    • CentOS/Fedora
  • Tips
    • docker 引擎开启远程访问
    • dockerfile-maven-plugin
    • IDEA 连接远程 docker
Powered by GitBook
On this page
  • 1. 创建工作目录
  • 2. 编写authorized_keys文件
  • 3. 编写Dockerfile
  • 4.创建镜像
  • 5.测试镜像,运行容器

Was this helpful?

Edit on GitHub
  1. 中间件安装
  2. 安装ssh服务

使用Dockerfile创建

1. 创建工作目录

$ mkdir ~/ssh_ubuntu

2. 编写authorized_keys文件

$ cat ~/.ssh/id_rsa.pub > ~/ssh_ubuntu/authorized_keys

3. 编写Dockerfile

$ vim Dockerfile

文件内容如下:

FROM ubuntu:18.04

LABEL MAINTAINER=zhang

USER root

RUN apt-get update &&\
        apt-get install -y openssh-server
RUN mkdir -p /var/run/sshd /root/.ssh
COPY authorized_keys /root/.ssh/authorized_keys 

EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]

4.创建镜像

$ docker build -t sshd:2.0 ~/ssh_ubuntu

$ docker images
REPOSITORY       TAG       IMAGE ID       CREATED         SIZE
sshd             2.0       2ce2cf1f5904   9 seconds ago   224MB

5.测试镜像,运行容器

$ docker run -d --name sshd -p 10223:22 sshd:2.0
e39bba79569d1ce7b37271b6d0d6b205bcd47ce8922c2983332207538852c180

$ ssh root@localhost -p 10223
The authenticity of host '[localhost]:10223 ([::1]:10223)' can't be established.
ECDSA key fingerprint is SHA256:1paj3O3XUCMDfiAnW2uOibArt89U1AY3T3w736tPTjg.
ECDSA key fingerprint is MD5:71:57:4c:2f:54:45:9b:cd:48:81:ee:4c:64:23:ec:09.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:10223' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 3.10.0-1160.el7.x86_64 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

root@e39bba79569d:~# 
Previous基于commit命令创建Next安装Apache

Last updated 1 year ago

Was this helpful?