标签:xfce .repo fda proc ges isa reg rmi 集成测试
原文:Docker基础Docker是一个开源的应用容器引擎,使用Go语言开发,基于Linux内核的CGroup、Namespace、Union FS等技术实现的一种系统级虚拟化技术。
安装需求:
由于Docker是建立在linux中两种核心技术之上:namespace与Cgroup,而User namespace出现的版本是3.8,所以安装docker需要内核版本大于3.10,centos6内核版本是2.6所以无法在其上使用docker。
namespace | 系统调用参数 | 隔离内容 | 内核版本 |
UTS | CLONE_NEWUTS | 主机名和域名 | 2.6.19 |
IPC | CLONE_NEWIPC | 信号量、消息队列和共享内存 | 2.6.19 |
PID | CLONE_NEWPID | 进程编号 | 2.6.24 |
Network | CLONE_NEWNET | 网络设备、网络栈、端口等 | 2.6.29 |
Mount | CLONE_NEWNS | 挂载点(文件系统) | 2.4.19 |
User | CLONE_NEWUSER | 用户和用户组 | 3.8 |
1. 安装依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
2.添加仓库
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
3. 查看docker版本列表
yum list docker-ce --showduplicates | sort -r
4. 安装指定版本的docker(可忽略,直接安装最新版)
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
5.安装最新版docker
yum install docker-ce docker-ce-cli containerd.io
1. 更新包管理
sudo apt-get update
2. 添加https包信任
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
3. 添加docker官方GPG 证书
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
4. 写入软件信息
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable”
4. 更新并安装docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
5.若安装指定版本采用如下方式
#列出版本 $ apt-cache madison docker-ce docker-ce | 5:18.09.1~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages docker-ce | 5:18.09.0~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages docker-ce | 18.06.1~ce~3-0~debian | https://download.docker.com/linux/debian stretch/stable amd64 Packages docker-ce | 18.06.0~ce~3-0~debian | https://download.docker.com/linux/debian stretch/stable amd64 Packages #安装 sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
停止防火墙、关闭selinux
systemctl stop firewalld && systemctl disable firewalld && setenforce 0
配置镜像加速
mkdir /etc/docker cat > /etc/docker/daemon.json <<EOF { "registry-mirrors": ["https://registry.docker-cn.com"] } EOF
运行docker
#重新装载systemd服务 systemctl daemon-reload #启动docker systemctl start docker #开机自动docker #systemctl enable docker #查看docker版本 [root@app51 ~]# docker version Client: Version: 18.09.2 API version: 1.39 Go version: go1.10.6 Git commit: 6247962 Built: Sun Feb 10 04:13:27 2019 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.2 API version: 1.39 (minimum version 1.12) Go version: go1.10.6 Git commit: 6247962 Built: Sun Feb 10 03:47:25 2019 OS/Arch: linux/amd64
其中docker container 则是管理容器命令,老的版本中是使用docker进行容器管理,新版本兼容老版本docker命令,所以对容器管理既可用docker也可以用docker container。
[root@app51 ~]# docker run -it --name nginx-container -p 8080:80 nginx /bin/bash root@fd92290433da:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
docker ps [OPTIONS]
root@app51 ~]# docker ps -n 2 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4d51a1cdf4b4 busybox "/bin/sh" 11 seconds ago Up 9 seconds busybox 383f31ff8f01 nginx "nginx -g ‘daemon of…" 3 minutes ago Up 3 minutes 0.0.0.0:8080->80/tcp nginx-container [root@app51 ~]# docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4d51a1cdf4b4 busybox "/bin/sh" 41 seconds ago Up 39 seconds busybox [root@app51 ~]#
docker inspect [OPTIONS] NAME|ID [NAME|ID…]
示例:
[root@app51 ~]# docker inspect busybox [ { "Id": "4d51a1cdf4b4e06831faa6e54a32f1f8eb544e349028083b12f5b3f87af075c9", "Created": "2019-02-23T09:10:20.907074902Z", "Path": "/bin/sh", "Args": [],
4.停止容器
[root@app51 ~]# docker stop nginx-container nginx-container
docker start [OPTIONS] CONTAINER [CONTAINER…]
[root@app51 ~]# docker start -ia busybox / # ls bin dev etc home proc root sys tmp usr var / # ps PID USER TIME COMMAND 1 root 0:00 /bin/sh 7 root 0:00 ps
docker rm nginx-container
Ps:删除所有容器
docker rm -f `docker ps -a -q` docker ps -a |awk -F ‘ ‘ ‘{print $1}‘ |xargs docker rm -f
docker pause CONTAINER [CONTAINER…]
示例:
[root@app51 ~]# docker pause nginx-container nginx-container
docker unpause CONTAINER [CONTAINER…]
[root@app51 ~]# docker pause nginx-container nginx-container
docker logs [OPTIONS] CONTAINER
常用选项:
root@app51 ~]# docker logs nginx-container 10.1.201.30 - - [23/Feb/2019:10:55:33 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36" "-"
示例:
[root@app51 ~]# docker exec -it -u nginx nginx-container /bin/sh $ id uid=101(nginx) gid=101(nginx) groups=101(nginx) $
[root@app51 ~]# docker export nginx-container -o nginx.tar [root@app51 ~]# ls -lh ningx.tar -rw------- 1 root root 107M 2月 23 19:18 ningx.tar
[root@app51 ~]# docker import nginx.tar nginx:v154 sha256:fd4931710d35765edb9bbd0ea84a886e0901aa7a2de03ab2eefd9aedea0e8646 [root@app51 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx v154 fd4931710d35 10 seconds ago 108MB <none> <none> 940cdf68f69d 7 minutes ago 108MB busybox latest d8233ab899d4 8 days ago 1.2MB nginx latest f09fe80eb0e7 2 weeks ago 109MB
其他导入示例
docker import http://example.com/image.tar.gz repository:tag
[root@app51 ~]# docker commit -p -m ‘build nginx image‘ nginx-container nginx:test sha256:6c68885804ca69970d747cc6cc8050ed7a1b6c24838695ec11b18348318809a6 [root@app51 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx test 6c68885804ca 6 seconds ago 109MB nginx v154 fd4931710d35 2 hours ago 108MB
在老版本中镜像操作也是使用的docker命令,新版本进行了分组,可使用docker image 来进行镜像操作。
docker search [OPTIONS] TERM
[root@app51 ~]# docker search centos NAME DESCRIPTION STARS OFFICIAL AUTOMATED centos The official build of CentOS. 5179 [OK] ansible/centos7-ansible Ansible on Centos7 120 [OK] jdeathe/centos-ssh CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x86… 106 [OK] consol/centos-xfce-vnc Centos container with "headless" VNC session… 80 [OK]
TAG不写默认为最新版本latest
[root@app51 ~]# docker pull centos Using default tag: latest latest: Pulling from library/centos a02a4930cb5d: Pull complete Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426 Status: Downloaded newer image for centos:latest
[root@app51 ~]# docker image ls -a REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 1e1148e4cc2c 2 months ago 202MB
docker image rm [OPTIONS] IMAGE [IMAGE...] 或者docker rmi IMAGE
[root@app51 ~]# docker image rm centos Untagged: centos:latest Untagged: centos@sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426 Deleted: sha256:1e1148e4cc2c148c6890a18e3b2d2dde41a6745ceb4e5fe94a923d811bf82ddb Deleted: sha256:071d8bd765171080d01682844524be57ac9883e53079b6ac66707e192ea25956
docker save [OPTIONS] IMAGE [IMAGE...]
[root@app51 ~]# docker save -o nginx-bus.tar.gz busybox:latest nginx:latest
常用选项:
[root@app51 ~]# docker load -i nginx-bus.tar.gz Loaded image: nginx:latest Loaded image: busybox:latest
docker image inspect [OPTIONS] IMAGE [IMAGE...]
[root@app51 ~]# docker image inspect nginx [ { "Id": "sha256:f09fe80eb0e75e97b04b9dfb065ac3fda37a8fac0161f42fca1e6fe4d0977c80", "RepoTags": [ "nginx:latest" ], "RepoDigests": [ "nginx@sha256:dd2d0ac3fff2f007d99e033b64854be0941e19a2ad51f174d9240dda20d9f534" ],
运行信息查看docker info
[root@app51 ~]# docker info Containers: 1 Running: 1 Paused: 0 Stopped: 0 Images: 4 Server Version: 18.09.2 Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true
版本信息查看 docker version
root@app51 ~]# docker version Client: Version: 18.09.2 API version: 1.39 Go version: go1.10.6 Git commit: 6247962 Built: Sun Feb 10 04:13:27 2019 OS/Arch: linux/amd64 Experimental: false
标签:xfce .repo fda proc ges isa reg rmi 集成测试
原文地址:https://www.cnblogs.com/lonelyxmas/p/10430201.html