|
<
初教docker容器
docker是甚么
- docker是一种沉量级的假造机
- 正在linux容器中运转使用并且开源
docker取假造机的区分
不同面容器假造机启动速率上秒级分钟级运转机能上靠近本死(间接运转正在内乱核中的90%)50%阁下的丧失数目根据历程,能够有许多历程成百上千个普通几十台(操纵系统级别)断绝历程级别系统级别(更完全的断绝)磁盘占用MBGB(操纵系统的镜像普通正在几个G阁下)操纵系统次要撑持linux险些局部系统启拆程度只挨包项目代码战依靠干系,同享宿主机内乱核完整的操纵系统,取宿主机相互断绝同时docker处理了vm的情况孤岛成绩,docker能够自界说通报参数
docker操纵场景
- 用去挨包使用法式简化布置
- 离开底层硬件随便迁徙
- 连续散成战连续托付(CI/CD):开辟到测试公布
- 布置微效劳
- 供给PAAS产品
docker的道理
cgroup资本掌握取namespace称号空间分离掌握办理6个称号空间资本完成完整断绝/完整断绝
- mount :文件系统,挂载面
- user :操纵历程的用户战用户组
- pid :历程编号
- uts :主机名战主机域
- ipc:旌旗灯号量,动静行列,同享内乱存(不同的使用挪用内乱存资本时操纵不同的内乱存空间)
- net:收集装备,收集和谈栈,端心等
该mount定名空间:办理文件系统挂载面
该pid定名空间:历程断绝(pid:历程id)
该uts定名空间:断绝内乱核战版本标识符(uts:Unix工夫同享系统)
该ipc定名空间:办理会见ipc资本(ipc:历程间相互通讯)
该net定名空间:办理收集接心(net:收集)
docker三个同一战docker三年夜组件
docker把容器化手艺做成了尺度化仄台
- docker引擎同一了根底设备情况—》docker情况
- docker引擎同一了法式挨包方法—》docker镜像
- docker引擎同一了法式布置方法—》docker容器–》基于镜像,运转为容器(可运转的情况)
完成了一次构建,屡次,多处操纵
三年夜组件:
- 镜像:做为模板,一组资本的汇合,包罗了使用法式硬件包,使用法式相干的依靠包,运转使用法式所需求的根底情况
- 容器:运转形态/运转时形态,基于镜像的一种运转时形态
- 仓库:寄存镜像模板的处所,仓库分类:大众仓库–》docker hub,公有仓库–》registry harbor
docker引擎
docker引擎具有以下次要组件的C/S使用法式(客户端-效劳器)
server端:效劳器是一种持久运转的法式,成为保护历程
client端:REST API指定法式能够用去取保护法式停止通讯并唆使其操纵的接心
docker-server设置文件
正在/etc/docker/daemon.json中设置
- {
- "graph":"/data/docker", //数据目次
- "storage-driver":"overlay2", //存储引擎
- "insecure-registries" ["registry.access.redhat.com","quary.io"] //公有堆栈
- "registry-mirrors": ["https://cn90fxk6.mirror.aliyuncs.com"] //镜像加快
- "bip":"172.17.0.1/24", //docker收集
- "exec-opts":["native.cgroupdriver=systemd"], //启动时的分外参数
- "live-restore":true //当docker容器存储引擎挂了后,利用docker跑起去的容器借能运转
- }
复造代码 docker的布置(20版)
- [root@node1 nginx]# yum install -y yum-utils device-mapper-persistent-data lvm2
复造代码
- [root@node1 yum.repos.d]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
复造代码
- [root@node1 yum.repos.d]# yum install -y docker-ce
复造代码
- [root@node1 yum.repos.d]# systemctl enable docker
- [root@node1 yum.repos.d]# systemctl start docker
复造代码
- 设置镜像放慢,来阿里云的镜像放慢分类
- 将底下的代码间接复造到号令止就能够了,要选对应的操纵系统
- 检察能否设置胜利
- [root@node1 yum.repos.d]# vim /etc/docker/daemon.json
- {
- "registry-mirrors": ["https://cn90fxk6.mirror.aliyuncs.com"]
- }
复造代码 docker镜像操纵
- [root@node1 yum.repos.d]# docker run hello-world
- Hello from Docker!
- This message shows that your installation appears to be working correctly.
- To generate this message, Docker took the following steps:
- 1. The Docker client contacted the Docker daemon. //客户端毗连到了效劳器
- 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. //由效劳真个保护历程从docker hub高低载了镜像
- (amd64)
- 3. The Docker daemon created a new container from that image which runs the
- executable that produces the output you are currently reading. //效劳端创立了一个新容器,然后从那个镜像启动了一个容器,容器施行了剧本
- 4. The Docker daemon streamed that output to the Docker client, which sent it
- to your terminal. //效劳端把那些疑息流返回到客户端展现出去
- To try something more ambitious, you can run an Ubuntu container with:
- $ docker run -it ubuntu bash
- Share images, automate workflows, and more with a free Docker ID:
- https://hub.docker.com/
- For more examples and ideas, visit:
- https://docs.docker.com/get-started/
复造代码
- [root@node1 yum.repos.d]# docker version
- Client: Docker Engine - Community
- Version: 20.10.8
- API version: 1.41
- Go version: go1.16.6
- Git commit: 3967b7d
- Built: Fri Jul 30 19:55:49 2021
- OS/Arch: linux/amd64
- Context: default
- Experimental: true
- Server: Docker Engine - Community
- Engine:
- Version: 20.10.8
- API version: 1.41 (minimum version 1.12)
- Go version: go1.16.6
- Git commit: 75249d8
- Built: Fri Jul 30 19:54:13 2021
- OS/Arch: linux/amd64
- Experimental: false
- containerd:
- Version: 1.4.9
- GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
- runc:
- Version: 1.0.1
- GitCommit: v1.0.1-0-g4144b63
- docker-init:
- Version: 0.19.0
- GitCommit: de40ad0
- [root@node1 yum.repos.d]# docker info
- Client:
- Context: default
- Debug Mode: false
- Plugins:
- app: Docker App (Docker Inc., v0.9.1-beta3)
- buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)
- scan: Docker Scan (Docker Inc., v0.8.0)
- Server:
- Containers: 14
- Running: 5
- Paused: 0
- Stopped: 9
- Images: 63
- Server Version: 20.10.8
- Storage Driver: overlay2
- Backing Filesystem: xfs
- Supports d_type: true
- Native Overlay Diff: true
- userxattr: false
- Logging Driver: json-file
- Cgroup Driver: cgroupfs
- Cgroup Version: 1
- Plugins:
- Volume: local
- Network: bridge host ipvlan macvlan null overlay
- Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
- Swarm: inactive
- Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
- Default Runtime: runc
- Init Binary: docker-init
- containerd version: e25210fe30a0a703442421b0f60afac609f950a3
- runc version: v1.0.1-0-g4144b63
- init version: de40ad0
- Security Options:
- seccomp
- Profile: default
- Kernel Version: 3.10.0-957.el7.x86_64
- Operating System: CentOS Linux 7 (Core)
- OSType: linux
- Architecture: x86_64
- CPUs: 4
- Total Memory: 5.712GiB
- Name: node1
- ID: QL6Y:HC6L:E57G:UWHJ:E7FY:J47A:YF6Z:GLL2:DETH:DY4C:STNH:ZGFS
- Docker Root Dir: /var/lib/docker
- Debug Mode: false
- Registry: https://index.docker.io/v1/
- Labels:
- Experimental: false
- Insecure Registries:
- 127.0.0.0/8
- Registry Mirrors:
- https://cn90fxk6.mirror.aliyuncs.com/
- Live Restore Enabled: false
- WARNING: bridge-nf-call-iptables is disabled
- WARNING: bridge-nf-call-ip6tables is disabled
复造代码
- [root@node1 yum.repos.d]# docker search nginx
- NAME DESCRIPTION STARS OFFICIAL AUTOMATED
- nginx Official build of Nginx. 15420 [OK]
- jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 2063 [OK]
- richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 816 [OK]
- jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 240
- linuxserver/nginx An Nginx container, brought to you by LinuxS… 152
- tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 141 [OK]
- jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 135 [OK]
- alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 106 [OK]
- jasonrivers/nginx-rtmp Docker images to host RTMP streams using NGI… 92 [OK]
- nginxdemos/hello NGINX webserver that serves a simple page co… 72 [OK]
- privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 56 [OK]
- nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo… 55
- nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 47
- staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 24 [OK]
- nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 20
- schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK]
- nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 19
- centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 15
- centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13
- bitwarden/nginx The Bitwarden nginx web server acting as a r… 11
- flashspys/nginx-static Super Lightweight Nginx Image 10 [OK]
- mailu/nginx Mailu nginx frontend 9 [OK]
- sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
- ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 2 [OK]
- wodby/nginx Generic nginx 1
- [root@node1 yum.repos.d]# docker search centos:7
- NAME DESCRIPTION STARS OFFICIAL AUTOMATED
- benwang6/tedu-jdk oracle jdk 8u281 centos:7 JAVA_HOME=/usr/jdk… 5
- vikingco/python Python Stack Docker Base Image: Based on cen… 1
- sndnvaps/docker-golang build latest golang in centos:7 1 [OK]
- legerete/nginx-php71 LA[->]P - Centos:7 + Nginx + PHP 7.1 1 [OK]
- peltikalle/basepython Base image with Centos:7 and Python 3.5.2 1 [OK]
- mjstealey/mariadb-galera MariaDB Galera cluster in Docker - based fro… 1 [OK]
- acktsw/java oracle jdk 8u171 , centos:7, timeZone:+8, e… 0 [OK]
- macedigital/nodejs Latest NodeJS for CentOS:7 0 [OK]
- grossws/nginx nginx (mainline) on grossws/centos:7 0 [OK]
- europeanspallationsource/oracle-jdk-maven-jenkins ICS oracle-jdk + maven + jenkins users image… 0
- pbieberstein/acic-findr CentOS:7 with dependencies to run 'Findr' (h… 0 [OK]
- sjoeboo/rbenv Simple base container from CentOS:7 w/ rbenv… 0 [OK]
- alvintz/centos centos:7.2.1511 0 [OK]
- geomatikk/centos FROM centos:7 with maven 3.6.1 and openjdk-1… 0
- waffleimage/centos7 Centos:7 with systemd and ssh running 0
- cristo/netacuity Docker image on Centos:7 to run NetAcuity 0 [OK]
- badwolf/centos from official centos:7 add gcc,gcc++,make,vi 0 [OK]
- mesosphere/freeipa-server A freeIPA v4.3 container based on centos:7. … 0
- acktsw/centos centos:7 0 [OK]
- bbania/centos Build image based on centos:7 0
- a2747/centos7 derivative images from centos:7 0
- 21plus2/server-jre Dockerimage base on centos:7 with server-jre 0 [OK]
- europeanspallationsource/oracle-jdk-maven ICS oracle-jdk + maven image based on centos… 0
- qiyue/mycat centos:7 + jdk:1.8 + mycat 0
- weihoop/mysql 基于weihoop/centos:7.4.1708建造
复造代码
- [root@node1 yum.repos.d]# docker pull nginx
- Using default tag: latest
- latest: Pulling from library/nginx
- a330b6cecb98: Pull complete
- 5ef80e6f29b5: Pull complete
- f699b0db74e3: Pull complete
- 0f701a34c55e: Pull complete
- 3229dce7b89c: Pull complete
- ddb78cb2d047: Pull complete
- Digest: sha256:a05b0cdd4fc1be3b224ba9662ebdf98fe44c09c0c9215b45f84344c12867002e
- Status: Downloaded newer image for nginx:latest
- docker.io/library/nginx:latest
- [root@node1 yum.repos.d]# docker images //检察镜像列表
- REPOSITORY TAG IMAGE ID CREATED SIZE
- nginx latest 822b7ec2aaf2 2 days ago 133MB
复造代码
- [root@node1 yum.repos.d]# docker inspect 822b7ec2aaf2
- [
- {
- "Id": "sha256:822b7ec2aaf2122b8f80f9c7f45ca62ea3379bf33af4e042b67aafbf6eac1941",
- "RepoTags": [
- "nginx:latest"
- ],
- "RepoDigests": [
- "nginx@sha256:a05b0cdd4fc1be3b224ba9662ebdf98fe44c09c0c9215b45f84344c12867002e"
- ],
- "Parent": "",
- "Comment": "",
- "Created": "2021-09-03T07:40:16.355730864Z",
- "Container": "367d32086ac12447d36e75c9b7acbe1b5156a34a91370b9200e68783be75506c",
- "ContainerConfig": {
- "Hostname": "367d32086ac1",
- "Domainname": "",
- "User": "",
- "AttachStdin": false,
- "AttachStdout": false,
- "AttachStderr": false,
- "ExposedPorts": {
- "80/tcp": {}
- },
- "Tty": false,
- "OpenStdin": false,
- "StdinOnce": false,
- "Env": [
- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
- "NGINX_VERSION=1.21.1",
- "NJS_VERSION=0.6.1",
- "PKG_RELEASE=1~buster"
- ],
- "Cmd": [
- "/bin/sh",
- "-c",
- "#(nop) ",
- "CMD ["nginx" "-g" "daemon off;"]"
- ],
- "Image": "sha256:d4315787e4fec867791beba140dd0e44f657cb6e4a9d75c676c7946089c20da9",
- "Volumes": null,
- "WorkingDir": "",
- "Entrypoint": [
- "/docker-entrypoint.sh"
- ],
复造代码
- [root@node1 yum.repos.d]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- nginx 123 822b7ec2aaf2 2 days ago 133MB
- nginx latest 822b7ec2aaf2 2 days ago 133MB
复造代码
- [root@node1 yum.repos.d]# docker rmi nginx:123
- Untagged: nginx:123
- [root@node1 yum.repos.d]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- nginx latest 822b7ec2aaf2 2 days ago 133MB
复造代码
- [root@node1 ~]# docker save -o nginx_images nginx:latest
- [root@node1 ~]# ls
- 12 1.sh 2333 45 apps initial-setup-ks.cfg ks.cfg nginx_images 模板 图片 下载 桌里
- 123 1.txt 234 anaconda-ks.cfg docker_home jdk-8u91-linux-x64.tar.gz nginx 大众 视频 文档 音乐
复造代码
- [root@node1 ~]# docker load < nginx_images
- d000633a5681: Loading layer [==================================================>] 72.53MB/72.53MB
- 63b5f2c0d071: Loading layer [==================================================>] 64.86MB/64.86MB
- 875b5b50454b: Loading layer [==================================================>] 3.072kB/3.072kB
- ed94af62a494: Loading layer [==================================================>] 4.096kB/4.096kB
- 8e58314e4a4f: Loading layer [==================================================>] 3.584kB/3.584kB
- d47e4d19ddec: Loading layer [==================================================>] 7.168kB/7.168kB
- Loaded image: nginx:latest
- [root@node1 ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- nginx latest 822b7ec2aaf2 2 days ago 133MB
复造代码
- [root@node1 ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
复造代码
- [root@node1 ~]# docker create -it nginx:latest /bin/bash
- 9eade02412f5ecc3e9e2006de2f59845ca50ed4a52741ad9f0a8fb43ce5086f3
- [root@node1 ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 9eade02412f5 nginx:latest "/docker-entrypoint.…" 3 seconds ago Created keen_chatterjee
- //-i是让容器的尺度输进连结翻开
- //-t是分派一个真末端
- //-d是背景保护历程的方法运转
复造代码
- [root@node1 ~]# docker start 9eade02412f5
- 9eade02412f5
- [root@node1 ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 9eade02412f5 nginx:latest "/docker-entrypoint.…" About a minute ago Up 2 seconds 80/tcp keen_chatterjee
复造代码
- [root@node1 ~]# docker run centos:7 /usr/bin/bash -c ls /
- anaconda-post.log
- bin
- dev
- etc
- home
- lib
- lib64
- media
- mnt
- opt
- proc
- root
- run
- sbin
- srv
- sys
- tmp
- usr
- var
复造代码
- [root@node1 ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 9eade02412f5 nginx:latest "/docker-entrypoint.…" 4 minutes ago Exited (137) 6 seconds ago //非0形态值皆是截至形态,137是stop号令截至的指数 keen_chatterjee
复造代码
- 进进容器,两种方法皆能够,可是exec需求正在容器运转时才气进进
- [root@node1 ~]# docker run -it nginx:latest /bin/bash
- root@d36a26b3e1d2:/#
- [root@node1 ~]# docker exec -it 9eade02412f5 /bin/bash
- root@9eade02412f5:/#
- docker run -it 会创立前台历程,可是会正在输进exit后停止历程
- docker exec -it 会毗连到容器,能够像ssh一样进进容器内乱部,停止操纵,能够经由过程exit退出
复造代码
- [root@node1 ~]# docker export 9eade02412f5 > nginx_1
- [root@node1 ~]# ls
- 12 1.sh 2333 45 apps initial-setup-ks.cfg ks.cfg nginx_1 大众 视频 文档 音乐
复造代码
- [root@node1 ~]# cat nginx_1 | docker import - nginx:latest
- sha256:ae834c84afd17bb12708bd2dd4d53e8432c43d6378d0ed405e1fd580dd6f77ad
复造代码
- [root@node1 ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 95b40e409895 nginx:latest "/bin/bash" 9 seconds ago Exited (0) 4 seconds ago sad_heyrovsky
- [root@node1 ~]# docker rm 95b40e409895
- 95b40e409895
- 强迫删除正正在运转中的容器能够减一个-f
复造代码
- [root@node1 ~]# docker ps -a | awk '{print "docker rm "$1}' | bash
- 3e0845eacc5c
- 5e0ecd151d57
- b8da82b16ba7
- 2930dd871f01
- 668103e78d6c
- 大概
- [root@node1 ~]# docker rm `docker ps -qa`
复造代码 免责声明:假如进犯了您的权益,请联络站少,我们会实时删除侵权内乱容,感谢协作! |
1、本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,按照目前互联网开放的原则,我们将在不通知作者的情况下,转载文章;如果原文明确注明“禁止转载”,我们一定不会转载。如果我们转载的文章不符合作者的版权声明或者作者不想让我们转载您的文章的话,请发帖留言提供原创证明,我们将积极配合您!
2、本网站转载文章仅为传播更多信息之目的,凡在本网站出现的信息,均仅供参考。本网站将尽力确保所提供信息的准确性及可靠性,但不保证信息的正确性和完整性,且不对因信息的不正确或遗漏导致的任何损失或损害承担责任。
3、任何透过本网站网页而链接及得到的资讯、产品及服务,本网站概不负责,亦不负任何法律责任。
4、本网站所刊发、转载的文章,其版权均归原作者所有,如其他媒体、网站或个人从本网下载使用,请在转载有关文章时务必尊重该文章的著作权,保留本网注明的“稿件来源”,并自负版权等法律责任。
|