Docker 学习

什么是 Docker?Docker与传统的虚拟机有什么区别?

  1. 传统虚拟机
    1.1 虚拟化硬件
    1.2 在电脑的硬件上做分割,弄出N个虚拟电脑来。
  2. Docker
    2.1 虚拟化操作系统
    2.2 虚拟化N个操作系统
  3. 虚拟概念图
    3.1 传统虚拟机
    传统虚拟机
    3.2 Docker
    Docker
    从以上解释中可以看出,传统虚拟机与Docker的不同,也就清楚了,Docker为什么是轻量级的应用容器框架(重点是容器)。而这也是传统虚拟机与Docker最大的不同。

在 Linux 下的 Docker

Linux下的Docker网上较多,那就不写在这里了吧~

在 windows 下的 Docker

Docker 命令

常用命令

?  user-portal git:(master) ? sudo docker build --help
Password:

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

Options:
      --build-arg list             Set build-time variables (default [])
      --cache-from stringSlice     Images to consider as cache sources
      --cgroup-parent string       Optional parent cgroup for the container
      --compress                   Compress the build context using gzip
      --cpu-period int             Limit the CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int              Limit the CPU CFS (Completely Fair Scheduler) quota
  -c, --cpu-shares int             CPU shares (relative weight)
      --cpuset-cpus string         CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string         MEMs in which to allow execution (0-3, 0,1)
      --disable-content-trust      Skip image verification (default true)
  -f, --file string                Name of the Dockerfile (Default is 'PATH/Dockerfile')
      --force-rm                   Always remove intermediate containers
      --help                       Print usage
      --isolation string           Container isolation technology
      --label list                 Set metadata for an image (default [])
  -m, --memory string              Memory limit
      --memory-swap string         Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --network string             Set the networking mode for the RUN instructions during build (default "default")
      --no-cache                   Do not use cache when building the image
      --pull                       Always attempt to pull a newer version of the image
  -q, --quiet                      Suppress the build output and print image ID on success
      --rm                         Remove intermediate containers after a successful build (default true)
      --security-opt stringSlice   Security options
      --shm-size string            Size of /dev/shm, default value is 64MB
      --squash                     Squash newly built layers into a single new layer
  -t, --tag list                   Name and optionally a tag in the 'name:tag' format (default [])
      --ulimit ulimit              Ulimit options (default [])

实用命令

进入容器内部查看文件目录

[root@localhost docker]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
806c175229ce        original:1.0        "/tomcat/bin/catal..."   20 hours ago        Up 5 seconds                8080/tcp            origin-debug
f04275ad9896        newtomcat:1.0       "/root/run.sh"           26 hours ago        Exited (137) 21 hours ago                       newtomcat_3
[root@localhost docker]# docker exec -it 806c /bin/bash

Linux 命令导出 Docker 日志

[root@localhost ~]# docker logs -->liuxudonglog.log dq-alert
[root@localhost ~]# [省略]...
[root@localhost ~]# [省略]...
[root@localhost ~]# ls
a.log  anaconda-ks.cfg  liuxudonglog.log  workspace  ws.log

日志在/root下

Docker 初步使用

  • docker 的第一次使用,完全可以 baidu 搜使用 docker toolbox 创建第一个容器 hello-world-nginx 服务器,真的不费劲,点点点就完了,像我这第一次用的,都没有搜什么,点几下之后,发现服务器起来啦,捂脸笑哭。

安装 Dcoker 环境

$ yum remove docker \
    docker-client \
    docker-client-lates \
    docker-common \
    docker-latest \
    docker-latest-logrotate \
    docker-selinux \
    docker-engine-selinux \
    docker-engine

$ yum install -y yum-utils \
    device-mapper-persistent-data \
    lvm2

$ yum-config-manager --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo 
    
$ yum install docker-ce

# 重新启动docker
$ systemctl restart docker

# 验证
$ docker version

安装 Docker-Compose(Docker 编排工具环境)

  • 一共两种
  1. curl 方式,也叫二进制方式,这个可以从 docker-compose 在 github 上的维护文档中找到最新版本的安装方式,推荐这个,比较方便。这个是维护地址
  2. pip 方式,这个没弄过,貌似是通过 python,个人不推荐,python 一旦更新版本,底层变化太大了。
  • 这里介绍 curl 安装方式,我安装的时候最新 Release 版本是 1.24.1
[root@spring-cloud-data-flow ~]# curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    480      0 --:--:--  0:00:01 --:--:--   480
100 15.4M  100 15.4M    0     0   241k      0  0:01:05  0:01:05 --:--:--  251k
[root@spring-cloud-data-flow ~]# chmod +x /usr/local/bin/docker-compose
[root@spring-cloud-data-flow ~]# docker-compose version
docker-compose version 1.24.1, build 4667896b
docker-py version: 3.7.3
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.0j  20 Nov 2018
  • docker-compose.yml主要关键字解释
  version: '2' # docker 的版本

  services: # 配置的容器列表

  CONTAINER_NAME: # 容器的名称

  image: BASE_IMAGE # 这个一个容器的基础镜像

  ports: # 你的容器需不需要做端口映射

  - "host_port:container_port"

  volumes: # 数据卷配置

  - host_dir:container_dir

  environment: # 环境变量(map 的配置方式 key: value)

  PARAM: VALUE

Docker 技术理解

Docker + Zookeeper 集群

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值