Basic Command Learning
1,docker Search CentOS # #搜索镜像文件
2,docker Pull CentOS # #下载镜像
3,docker Images # #查看镜像
4,docker run Centos/bin/echo ' Hello World ' # #启动一个容器
5,docker Ps-a # #查看容器包括启动和停止的容器
6,docker run--name mydocker-it Centos/bin/bash # #进入容器内部
7, IP ad li # #查看ip地址
8,docker run-d--name mydocker CentOS # #后台启动容器
9,nsenter (yum-y install util-linux) # #使用这个命令通过容器 PID into the container
Docker Inspect--format "{{. State.pid}} "Mydocker (name or container id) 3575 # #取得容器的PID号
10,nsenter--target 3575--mount--uts--ipc--net--pid # #进入容器
To enter the container script:
#!/bin/bash
Cname=$1
Cpid= ' Docker inspect--format ' {{. State.pid}} "$CNAME"
Nsenter--target "$CPID"--mount--uts--ipc--net--pid
Network access:
1, brctl show # #会发现一个docker0的网桥
2, IP ro li # #查看路由
3, Network port mapping:
Random mapping:
Docker-d-P--name mynginx nginx
Docker ps-l# #查看最近的一个容器操作
Onds 0.0.0.0:32769->80/tcp,0.0.0.0:32768->443/tcp Mynginx # #容器的80端口映射到物理机的32769
Specify the mappings:
Docker-d-P 91:80--name mynginx1 nginx # #91是映射后的端口, 80 is the default port in the container
-P Ip:hostPort:containerPost # #ip地址端口 + container port
-P Ip::containerport # #iP + container port
-P hostport:containerport-p Hostport:containerpor # #指定多个端口
Docker Data management:
Data Volume:-v/data
Docker run-it--name volume-test1-h centos-v/data CentOS # #在容器里会生成一个/data Directory
Docker Inspect-f {{. Volumes}} Volume-test1 # #查看数据目录映射关系
Specify directory:-v SRC:DST
Docker run-it--name volume-test2-h centos-v/opt:/opt (: Ro Read only) CentOS # #物理机的/opt map to Container/opt
Docker run-it--rm CentOS # #此镜像为测试镜像关闭后自动清楚
Data Volume Container:
Docker run-it--name volume-test3--volumes-from volume-test1 CentOS # #指定容器1, for data volumes
Docker Image build:
Build manually:
1,nginx plus daemon off; Turn off Nginx background run and set the boot/etc/rc.d/rc.local
2,docker commit-m "My_nginx" 023d0bc923a9 dihaifeng/my_nginx:v1 # #将容器制作成镜像
3,docker run-d-P 99:80 Dihaifeng/my_nginx:v1/usr/local/nginx/sbin/nginx
Dockfile:
1, base image Information 2, maintainer information 3, mirror operation instruction 4, container start execution instruction
1, create the Dockerfile directory
Mkdir-p/opt/docker-file/nginx
Vim Dockerfile # #docker的D必须大写
Dockerfile directive:
From: Who is it's mother (base image)
Maintainer: Tell someone that you created it (maintainer information)
ADD: Put some files in his belly (copy file, will be automatically extracted, must and Dockerfile in a directory)
Run: What do you want it to do (add the command in front of the run)
Workdir: I'm a CD, I just made makeup today (current working directory)
VOLUME: Give me a place to store my luggage (catalogue mount)
EXPOSE: What is the door I want to open (port)
Run: Run, brother! (process continues to run)
To configure DOCKERFLE environment variables:
ENV Path=/usr/local/nginx/sbin: $PATH
CMD ["Nginx"]
Docker build-t nginx-file:v1/opt/docker-file/nginx/# #自动构建dockerfile
Docker Core Technology:
Docker resource isolation: Using Linux LXC, using kernel namespace (namespaces: Pid, Net, IPC, MNT, UTS, user)
Docker resource limit: Use Cgroup, support CPU, memory
Tools for stress Testing: stress
CPU test:
Docker run-it--rm stress--cpu 1 # #开一个容器测试cpu占用率
Docker run-it--rm-c stress-cpu 1 # #有几个CPU指定几, CPU quota test, not specified by default is half-divided
Docker run-it--rm--cpuset-cpus=0,1 Stress--cpu 2 # #只会占用一个CPU
Memory test:
Docker run-it--rm-m 128m stress--vm 1--vm-bytes 120m--vm-hang 0
Docker Network mode: The default is Bridge mode. Docker-compose # #构建多个镜像
Docker-registry Private Warehouse:
Docker Pull Registry
Docker run-d-P 5001:5000 Registry # #registry默认是5000端口
Docker tag Nginx 192.168.10.110:5001/test/nginx:v1 # #打标签
Docker Push 192.168.10.110:5001/test/nginx:v1 # #打完标签可以push到私有仓库中, the new version will error, to use the way HTTPS,
Modify/etc/sysconfig/docker---> other_args= "--insecure-registry 192.168.10.110:5001" to restart Docker, you can push.
Docker Dashboard (Shipyard):
1,vim/etc/sysconfig/docker
other_args= "-H tcp://0.0.0.0:235-h unix:///var/run/docker.sock" # #容器之间通信
/etc/init.d/docker Restart #重新加载docker
2, install shipyard
Docker run-it-d--name shipyard-rethinkdb-data--entrypoint/bin/bash shipyard/rethinkdb-l
This article is from the "Henry" blog, please be sure to keep this source http://dihaifeng.blog.51cto.com/8814208/1713512
Docker Basic Learning