文章目录
什么是 Docker?Docker与传统的虚拟机有什么区别?
- 传统虚拟机
1.1 虚拟化硬件
1.2 在电脑的硬件上做分割,弄出N个虚拟电脑来。 - Docker
2.1 虚拟化操作系统
2.2 虚拟化N个操作系统 - 虚拟概念图
3.1 传统虚拟机
3.2 Docker
从以上解释中可以看出,传统虚拟机与Docker的不同,也就清楚了,Docker为什么是轻量级的应用容器框架(重点是容器)。而这也是传统虚拟机与Docker最大的不同。
在 Linux 下的 Docker
Linux下的Docker网上较多,那就不写在这里了吧~
在 windows 下的 Docker
- windows 7 docker 如何在tomcat容器中部署Javaweb项目
- Windows10下的 docker 安装与入门 (一)使用 docker toolbox 安装docker
- Windows10下的 docker 安装与入门 (二)使用 docker 引擎在容器中运行镜像
- Windows10下的 docker 安装与入门 (三) 创建自己的 docker 镜像并且在容器中运行它
- DaoCloud | Docker 官网(时常打不开,多从不同的地方试着打开就好了,实在不行,可以用百度快照进入下载)
- 如果你在虚拟机中启动 Docker Quickstart Terminal 失败的话,很有可能是你的虚拟机 CPU 虚拟化没有启动,按照此链接可以看到虚拟机里虚拟化技术的设置方式。
- 如果你的虚拟机按照上面链接设置虚拟化后报 CPU 虚拟计数器之类的错误的话,那就将上面说的两个虚拟化设置找中的虚拟计数器选项去掉就可以了。
- 初次启动 docker 的时候确实挺慢的,如果你启动的时候卡在 waiting for an IP 不动了的话,可以参照这个链接的回答解决
- 这个是 docker 官方的资料,这一篇主要介绍如何安装 docker for windows 耐心看到后面一点的时候你会发现 Docker for Windows Installer.exe 的下载地址,注意,这个工具只能用在 windows 10 64位的操作系统上
- 这里是 docker 官方 Windows 的下载链接
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
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 编排工具环境)
- 一共两种
- curl 方式,也叫二进制方式,这个可以从 docker-compose 在 github 上的维护文档中找到最新版本的安装方式,推荐这个,比较方便。这个是维护地址
- 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