zoukankan      html  css  js  c++  java
  • DOCKER实战案例

    操作系统:
    [root@yz6205 ~]# docker search busybox
    NAME DESCRIPTION STARS OFFICIAL AUTOMATED
    busybox Busybox base image. 675 [OK]
    progrium/busybox 61 [OK]
    radial/busyboxplus Full-chain, Internet enabled, busybox made... 11 [OK]
    odise/busybox-python 3 [OK]


    [root@yz6205 ~]# docker pull busybox
    latest: Pulling from busybox
    56ed16bd6310: Pull complete
    bc744c4ab376: Pull complete
    Digest: sha256:4a887a2326ec9e0fa90cce7b4764b0e627b5d6afcb81a3f73c85dc29cea00048
    Status: Downloaded newer image for busybox:latest

    运行busybox
    [root@yz6205 ~]# docker run -it busybox
    / # grep
    BusyBox v1.24.2 (2016-03-18 16:38:06 UTC) multi-call binary.

    Usage: grep [-HhnlLoqvsriwFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...

    Search for PATTERN in FILEs (or stdin)


    查看mount挂载信息
    / # mount
    rootfs on / type rootfs (rw)
    /dev/sda5 on / type ext4 (rw,relatime,data=ordered)
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    tmpfs on /dev type tmpfs (rw,nosuid,mode=755)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)


    修改Docker镜像的存储位置
    http://blog.chinaunix.net/uid-20788636-id-4988546.html

    创建容器:
    [root@yz6205 ~]# docker run -ti ubuntu:14.04 /bin/bash
    Unable to find image 'ubuntu:14.04' locally
    Repository ubuntu already being pulled by another client. Waiting.
    ^C[root@yz6205 ~]# docker run -ti ubuntu /bin/bash
    Unable to find image 'ubuntu:latest' locally
    latest: Pulling from ubuntu
    e9a1b385b0f6: Pull complete
    92a77738f25d: Pull complete
    e9f6d47ace10: Pull complete
    b873f334fa52: Pull complete
    7bd023c8937d: Pull complete
    Digest: sha256:180f2869a492795d44a49bf4de244fde9f8d71db3c697c30600ef284ecb92bff
    Status: Downloaded newer image for ubuntu:latest
    root@6ab086fc9c3d:/#

    配置软件源
    root@6ab086fc9c3d:/# apt-get update
    Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
    Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [94.5 kB]
    Get:3 http://archive.ubuntu.com/ubuntu xenial-security InRelease [94.5 kB


    root@6ab086fc9c3d:/# apt-get install curl
    root@6ab086fc9c3d:/# curl
    curl: try 'curl --help' or 'curl --manual' for more information

    root@6ab086fc9c3d:/# service apache2 start
    * Starting Apache httpd web server apache2 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.1. Set the 'ServerName' directive globally to suppress this message
    *
    root@6ab086fc9c3d:/# apt-get install apache2root@6ab086fc9c3d:/# curl 127.0.0.1:80

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    按照配置ssh
    root@6ab086fc9c3d:/# apt-get install openssh-server
    root@6ab086fc9c3d:/# mkdir -p /var/run/sshd
    root@6ab086fc9c3d:/# /usr/sbin/sshd -D &
    [1] 4806

    root@6ab086fc9c3d:/# ps -ef |grep sshd
    root 4806 1 0 13:59 ? 00:00:00 /usr/sbin/sshd -D

    修改ssh服务的安全登陆配置,取消pam登陆限制
    root@6ab086fc9c3d:/# sed -ri 's/session required pam_loginuid.so/#session required.so/g' /etc/pam.d/sshd
    root@6ab086fc9c3d:/# mkdir root/.ssh
    root@6ab086fc9c3d:/# ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): y
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in y.
    Your public key has been saved in y.pub.
    The key fingerprint is:
    SHA256:1OWc3jyk6bATo0fzU6Y0zsVgKFIXCvMchOTP3X9ZbI4 root@6ab086fc9c3d
    The key's randomart image is:
    +---[RSA 2048]----+
    | .+o+ o.. |
    | ..* = = . |
    | o * o * . |
    | = o + O . |
    | S B B O +|
    | o % B =o|
    | . + B E.o|
    | . . . . |
    | |
    +----[SHA256]-----+
    root@6ab086fc9c3d:/# exit
    exit

    保存镜像

    [root@yz6205 ~]# docker commit 6ab sshd:ubuntu
    c82423c91c84b326afe47bbc475939e76637bfa42445318fe9b2afba01e0453d

    [root@yz6205 ~]# docker images
    REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
    sshd ubuntu c82423c91c84 47 seconds ago 332 MB
    ubuntu latest 7bd023c8937d 5 days ago 122 MB

    使用镜像
    [root@yz6205 ~]# docker run -p 10022:22 -d sshd:ubuntu /run.sh
    9ea4fd0fe1fc1636a622dcc4ae3457a3fcb7d0215441121e78172fad9e20dbc2

    [root@yz6205 ~]# docker ps -l
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    9ea4fd0fe1fc sshd:ubuntu "/run.sh" About a minute ago Exited (0) 41 seconds ago tender_swartz

  • 相关阅读:
    C# WinForms多线程编程-摇奖程序
    C#多线程编程实例介绍
    C#多线程编程(1) —— 多线程与UI操作
    C#引用类型与值类型浅析
    HTML中空格占位符的几种方式
    C#中字符串排序的问题和解决方法
    InstanceContextMode和ConcurrencyMode的默认值
    The "IsFileSystemCaseSensitive" parameter is not supported by the "FindConfigFiles" task
    jQuery中delegate() 和 on()的出现版本
    NHibernate 分页优化,针对SQLServer(未深入测试)
  • 原文地址:https://www.cnblogs.com/liyongsan/p/5544413.html
Copyright © 2011-2022 走看看