分类: Docker

  • 使用Docker搭建zabbix平台

        1.准备安装好zabbix服务的镜像

     

    docker pull docker.io/berngp/docker-zabbix

    下载镜像如下所示:

    docker pull docker.io/berngp/docker-zabbix

     

        2.宿主机中启动Docker

     

           docker启动zabbix时,需要绑定宿主机的端口,启动命令如下:
    docker run -d \
              -p 10051:10051 \
              -p 10052:10052 \
              -p 7777:80       \
              -p 2812:2812   \
              --name zabbix  \
              berngp/docker-zabbix

              

  • 使用docker搭建kafka集群

    IP
    zookeeper
    kafka
    192.168.151.33 zookeeper.1(2181,2888,3888) broker.1(9092,9093)
    192.168.151.38 zookeeper.2(2181,2888,3888) broker.2(9092,9093)
    192.168.151.40 zookeeper.3(2181,2888,3888) broker.3(9092,9093)
    192.168.151.41 broker.4(9092,9093)

    Docker镜像

    # docker pull hyperledger/fabric-zookeeper
    # docker pull hyperledger/fabric-kafka

     

    docker-compose.yaml

     

    version: '2'
    services:
        zookeeper:
            image: hyperledger/fabric-zookeeper
            restart: always
            ports:
                2181:2181
                2888:2888
                3888:3888
            environment:
                ZOO_MY_ID: 1
                ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=192.168.151.38:2888:3888 server.3=192.168.151.40:2888:3888
     
        kafka:
            image: hyperledger/fabric-kafka
            restart: always
            ports:
                9092:9092
                9093:9093
            environment:
                KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
                KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE: "false"
                KAFKA_DEFAULT_REPLICATION_FACTOR: 3
                KAFKA_MIN_INSYNC_REPLICAS: 2
                KAFKA_MESSAGE_MAX_BYTES: 1000000
                KAFKA_REPLICA_FETCH_MAX_BYTES: 1000000
                KAFKA_LOG_RETENTION_MS: -1
                KAFKA_ADVERTISED_HOST_NAME: "192.168.151.45"
                KAFKA_ADVERTISED_PORT: 9092
                KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://192.168.151.45:9092"
                KAFKA_BROKER_ID: 1
    # docker-compose up -d

     

     

  • docker基础操作

    docker基础命令

    容器

    创建一个新容器但不启动

    1
    docker create <image-id>   为镜像添加一个可读写层,构成一个容器(并未运行)。

    参数

    启动终止状态的容器

     

    1
    docker start <container-id>    为容器文件系统创建一个进程隔离空间(每个容器只能有一个进程隔离空间)。

     

    参数

    -i    附着到容器的标准输入

    基于镜像新建一个容器并启动

     

    1
    docker run 等于是docker create和docker start两个命令的集合

     

    操作流程

        • 检查本地是否存在指定的镜像,不存在就从公有仓库下载
        • 利用镜像创建并启动一个容器
        • 分配一个文件系统,并在只读的镜像层外面挂载一层可读写层
        • 从宿主主机配置的网桥接口中桥接一个虚拟接口到容器中去
        • 从地址池配置一个 ip 地址给容器
        • 执行用户指定的应用程序
        • 执行完毕后容器被终止

    参数

    -i    让容器的标准输入保持打开

    -t    分配一个伪终端并绑定到容器的标准输入上

    -d    将容器在后台运行

    停止容器

     

    1
    docker stop <container-id>    向运行中的容器发送一个SIGTERM信号,然后停止所有的进程

    参数

    -t    指定等待n秒后停止容器(默认为10)

    1
    docker kill <container-id>    向运行中的容器发送一个不友好的SIGKILL信号,然后停止所有的进程

    参数

    -s    发送指定信号到容器(默认为KILL)

    删除容器

    1
    docker rm <container-id>    删除构成容器的可读写层

    docker rm默认不会删除正在运行的容器

    参数

    -f    强制删除一个正在运行的容器(使用SIGKILL信号)

    将容器转换为镜像

    1
    docker commit <container-id>    将容器的可读可写层转换成一个只读层,这样就把一个容器转换成了镜像

    docker rm默认不会删除正在运行的容器

    参数

    -f    强制删除一个正在运行的容器(使用SIGKILL信号)

    查看容器整体信息

    1
    docker ps

    参数

    -a    显示所有容器(默认只显示正运行的)

    -q    只显示容器ID

    -n n    只显示最近n个容器信息

    -s    显示容器使用的磁盘空间

    查看容器或镜像详细信息

    1
    docker instpect <container-id>或<image-id>

     

    镜像

    镜像命令

    1
    docker images 查看

     

    参数

    -a    显示所有镜像

    -f    根据条件过滤要显示的镜像

    -q    只显示镜像ID

     

    删除镜像的只读层

    1
    docker rmi <image-id>    删除构成容器的一个或多个可读层(删除最顶层的唯一方法)

    参数

    -f    强制删除一个镜像

    查看镜像的历史镜像

    1
    docker history <image-id>    递归地输出指定镜像的历史镜像
  • upubtu下,将docker1.4升级到1.9

    # docker -v
    # apt-get update
    # apt-get -u -y upgrade lxc-docker

  • Docker 和 Lxc的异同

    Docker is not a replacement for lxc. “lxc” refers to capabilities of the linux kernel (specifically namespaces and control groups) which allow sandboxing processes from one another, and controlling their resource allocations.

    On top of this low-level foundation of kernel features, Docker offers a high-level tool with several powerful functionalities:

    • Portable deployment across machines. Docker defines a format for bundling an application and all its dependencies into a single object which can be transferred to any docker-enabled machine, and executed there with the guarantee that the execution environment exposed to the application will be the same. Lxc implements process sandboxing, which is an important pre-requisite for portable deployment, but that alone is not enough for portable deployment. If you sent me a copy of your application installed in a custom lxc configuration, it would almost certainly not run on my machine the way it does on yours, because it is tied to your machine’s specific configuration: networking, storage, logging, distro, etc. Docker defines an abstraction for these machine-specific settings, so that the exact same docker container can run – unchanged – on many different machines, with many different configurations.
    • Application-centric. Docker is optimized for the deployment of applications, as opposed to machines. This is reflected in its API, user interface, design philosophy and documentation. By contrast, the lxc helper scripts focus on containers as lightweight machines – basically servers that boot faster and need less ram. We think there’s more to containers than just that.
    • Automatic build. Docker includes a tool for developers to automatically assemble a container from their source code, with full control over application dependencies, build tools, packaging etc. They are free to use make, maven, chef, puppet, salt, debian packages, rpms, source tarballs, or any combination of the above, regardless of the configuration of the machines.
    • Versioning. Docker includes git-like capabilities for tracking successive versions of a container, inspecting the diff between versions, committing new versions, rolling back etc. The history also includes how a container was assembled and by whom, so you get full traceability from the production server all the way back to the upstream developer. Docker also implements incremental uploads and downloads, similar to “git pull”, so new versions of a container can be transferred by only sending diffs.
    • Component re-use. Any container can be used as an “base image” to create more specialized components. This can be done manually or as part of an automated build. For example you can prepare the ideal python environment, and use it as a base for 10 different applications. Your ideal postgresql setup can be re-used for all your future projects. And so on.
    • Sharing. Docker has access to a public registry (https://registry.hub.docker.com/) where thousands of people have uploaded useful containers: anything from redis, couchdb, postgres to irc bouncers to rails app servers to hadoop to base images for various distros. The registry also includes an official “standard library” of useful containers maintained by the docker team. The registry itself is open-source, so anyone can deploy their own registry to store and transfer private containers, for internal server deployments for example.
    • Tool ecosystem. Docker defines an API for automating and customizing the creation and deployment of containers. There are a huge number of tools integrating with docker to extend its capabilities. PaaS-like deployment (Dokku, Deis, Flynn), multi-node orchestration (maestro, salt, mesos, openstack nova), management dashboards (docker-ui, openstack horizon, shipyard), configuration management (chef, puppet), continuous integration (jenkins, strider, travis), etc. Docker is rapidly establishing itself as the standard for container-based tooling.

    摘自:http://stackoverflow.com/questions/17989306/what-does-docker-add-to-lxc-tools-the-userspace-lxc-tools

Copyright © 2014-2025 奋奋的愤愤 | 京ICP备14029030号-1