容器引擎 Docker

发布于 2020-04-02 作者 风铃 242次 浏览 版块 后端

什么是 Docker?

Docker™ provides a way to run applications securely isolated in a container, packaged with all its dependencies and libraries.

环境搭建

MacOS

1 $ brew cask install docker

Windows

下载

 从 Toolbox 的 archive 页面找到 DockerToolbox-1.13.1.exe 并下载(官方地址

安装

 注意安装组件的时候,选择 Full installation,其他的均使用默认的选项,即可

配置

代理
1 $ vim ~/.docker/config.json
123456789 { "proxies": { "default": { "httpProxy": "socks5://127.0.0.1:1080", "httpsProxy": "socks5://127.0.0.1:1080", "noProxy": "*.yuzhouwan.com" } }}
镜像源
12 https://docker.mirrors.ustc.edu.cnhttps://hub-mirror.c.163.com
配置文件
1 $ vim ~/.docker/config.json
12345 { "registry-mirrors": [ "https://registry.docker-cn.com" ]}
命令行指定
1 $ docker-machine create --engine-registry-mirror=http://hub-mirror.c.163.com -d virtualbox kafka-connect
Desktop 设置

(对 Docker™ 的截图)

Boot 2 Docker

  • 打开 cmd 命令行

1 $ cmd
  • 查看帮助文档

1 $ docker-machine -h
  • 创建名为 kafka-connect 的镜像

1 $ docker-machine create --driver virtualbox kafka-connect
  • 进入 kafka-connect 镜像

1 $ docker-machine env kafka-connect
1234567 SET DOCKER_TLS_VERIFY=1SET DOCKER_HOST=tcp://127.0.0.1:2376SET DOCKER_CERT_PATH=C:\Users\BenedictJin\.docker\machine\machines\kafka-connectSET DOCKER_MACHINE_NAME=kafka-connectSET COMPOSE_CONVERT_WINDOWS_PATHS=trueREM Run this command to configure your shell:REM @FOR /f "tokens=*" %i IN ('docker-machine env kafka-connect') DO @%i
  • 拷贝上面输出的最后一行,去掉 REM 注释,并运行

1 $ @FOR /f "tokens=*" %i IN ('docker-machine env kafka-connect') DO @%i
  • 此时,就可以执行 docker 相关的命令了

1 $ docker info
  • 移除 kafka-connect 镜像

1 $ docker-machine rm kafka-connect

常用命令

version

1 $ docker version
123456789101112131415161718192021222324252627 Client: Docker Engine - Community Version: 19.03.5 API version: 1.40 Go version: go1.12.12 Git commit: 633a0ea Built: Wed Nov 13 07:22:34 2019 OS/Arch: darwin/amd64 Experimental: falseServer: Docker Engine - Community Engine: Version: 19.03.5 API version: 1.40 (minimum version 1.12) Go version: go1.12.12 Git commit: 633a0ea Built: Wed Nov 13 07:29:19 2019 OS/Arch: linux/amd64 Experimental: false containerd: Version: v1.2.10 GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339 runc: Version: 1.0.0-rc8+dev GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657 docker-init: Version: 0.18.0 GitCommit: fec3683

status

1 $ service docker status
12345678910 Redirecting to /bin/systemctl status docker.service● docker.service - LSB: start and stop docker Loaded: loaded (/etc/docker/docker; enabled; vendor preset: disabled) Active: active (running) since Tue 2018-09-18 09:54:31 CST; 29min ago Docs: man:systemd-sysv-generator(8) Process: 14743 ExecStart=/etc/docker/docker start (code=exited, status=0/SUCCESS) CGroup: /docker.slice/docker.service ├─14907 /opt/ali-iaas/docker/plugins/alinet 127.0.0.1 ├─14919 /opt/ali-iaas/docker/plugins/tmpfs 127.0.0.1 └─14933 /opt/ali-iaas/docker/plugins/alilocal 127.0.0.1

logs

1 $ docker logs -f <容器名 or 容器ID>

login

1 $ docker login reg.docker.yuzhouwan.com

cp

1234 # 从容器中将文件拷贝出来$ docker cp <容器名 or 容器ID>:/home/benedict_jin/a.txt /opt/# 从将文件拷贝到容器里面$ docker cp /opt/ <容器名 or 容器ID>:/home/benedict_jin/a.txt

run

| 1 | $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...] |
| —- | ———————————————————— |
| | |

restart

1 $ docker restart <容器名 or 容器ID>

踩到的坑

No default Boot2Docker ISO found locally

描述

1 $ docker-machine create --driver virtualbox kafka-connect
123 Running pre-create checks...(dataagg) No default Boot2Docker ISO found locally, downloading the latest release...Error with pre-create check: "Get https://api.github.com/repos/boot2docker/boot2docker/releases/latest: dial tcp 127.0.0.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."

解决

 到 boot2docker 的 release 页面下载最新的 boot2docker.iso(当前最新版本为 v17.12.1-ce),并放到 C:\Users\BenedictJin\.docker\machine\cache 目录下,再次运行 docker-machine create xxx 命令即可

Docker.raw 单文件达到 64G

描述

1 $ ll -h /Users/benedictjin/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
1 -rw-r--r-- 1 benedictjin staff 64G 3 23 22:18 /Users/benedictjin/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw

解决

 进入 Preferences 配置页面,选择 Disk 配置页,调整预分配磁盘大小,点击 Apply 按钮以应用修改

资料

Doc

Github

Resource

收藏
暂无回复