#########################################docker event state#########################################linux
[root@centos7-5-01 ~]# docker versionnginx
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: falsedocker
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
Experimental: false
[root@centos7-5-01 ~]# docker info
Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 1
Server Version: 18.09.2
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
runc version: 09c8266bf2fcf9519a651b04ae54c967b9ab86ec
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-862.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.779GiB
Name: centos7-5-01
ID: 2OY6:GLOK:FYFW:4VP2:H5H5:JDHQ:DEGU:C7FB:7QY7:4MJH:E2Z6:KQKI
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Enginejson
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabledcentos
###############鏡像的導入和導出############### bash
#第一種方法tcp
#導出
docker save -o centos.tar centos
#導入
docker load --input centos.tarui
#第二種方法centos7
#################################docker常見操做命令######################################spa
#-d後臺啓動,若是沒有這個鏡像,會自動幫你pull
#-t分配個僞終端,能夠登陸進去;-i 僞終端能夠保持打開狀態
[root@centos7-5-01 ~]# docker run --name mydocker -i -t centos /bin/bash
#-d啓動容器,讓他在後臺運行,若是你本機沒有nginx鏡像,他會自動去獲取nginx鏡像
[root@centos7-5-01 ~]# docker run -d --name mynginx nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from nginx
1cb018da208f: Pull complete
c1a0d2b79b3f: Pull complete
0aec54b378f5: Pull complete
b599d18a520b: Pull complete
a1cfc1b806a4: Pull complete
c2504687d157: Pull complete
a00416541f84: Pull complete
6adf11c406b6: Pull complete
9daddd1b8b0f: Pull complete
036477bc0d5a: Pull complete
Digest: sha256:248f3c1a01b35a098c85b31c356787068b1c1adbbd2f902fb2d6f49b95fd380f
Status: Downloaded newer image for nginx:latest
0c0c2a5e9f665e0a662177ce3d52a7907346ea66ab40a53d66e067511f7ca5a9
#查看運行的容器
[root@centos7-5-01 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0c0c2a5e9f66 nginx "nginx -g 'daemon of 7 seconds ago Up 7 seconds 80/tcp mynginx
481b2fa0cf72 centos "/bin/bash" 2 minutes ago Exited (0) 2 minutes ago mydocker2
0fd35d91742b centos "/bin/bash" 7 minutes ago Exited (127) 6 minutes ago mydocker
#刪除運行的容器
[root@centos7-5-01 ~]# docker rm mydocker
mydocker
[root@centos7-5-01 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0c0c2a5e9f66 nginx "nginx -g 'daemon of About a minute ago Up About a minute 80/tcp mynginx
481b2fa0cf72 centos "/bin/bash" 3 minutes ago Exited (0) 3 minutes ago mydocker2
#中止運行的容器
[root@centos7-5-01 ~]# docker stop 0c0c2a5e9f66
0c0c2a5e9f66
[root@m68en-s000 game]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0c0c2a5e9f66 nginx "nginx -g 'daemon of 2 minutes ago Exited (0) 29 seconds ago mynginx
481b2fa0cf72 centos "/bin/bash" 4 minutes ago Exited (0) 4 minutes ago mydocker2
######################進入運行中的容器#############################
#這個進去容器的命令很差用,有的時候進不去,只能Ctrl+C強制終止,這樣容器的狀態會自動退出了
[root@centos7-5-01 ~]# docker attach mynginx
######exec也能夠進去,但有時會出現問題
docker exec -it mydocker /bin/sh
#最後容器的狀態
[root@centos7-5-01 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cd15d1249f8f nginx "nginx -g 'daemon of 3 minutes ago Exited (0) About a minute ago mynginx
[root@centos7-5-01 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cd15d1249f8f nginx "nginx -g 'daemon of 3 minutes ago Exited (0) About a minute ago mynginx
#啓動容器 ,推薦使用下面的命令進入容器
[root@centos7-5-01 ~]# docker start cd15d1249f8f
cd15d1249f8f
[root@centos7-5-01 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cd15d1249f8f nginx "nginx -g 'daemon of 5 minutes ago Up 1 seconds 80/tcp mynginx
#util-linux包有這個命令nsenter
#獲取容器的pid,使用nsenter命令進入容器
[root@centos7-5-01 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cd15d1249f8f nginx "nginx -g 'daemon of 5 minutes ago Up 1 seconds 80/tcp mynginx
[root@centos7-5-01 ~]# docker inspect --format "{{.State.Pid}}" cd15d1249f8f
3451
[root@centos7-5-01 ~]# nsenter --target 3451 --mount --uts --ipc --net --pid
#腳本進入,腳本以下
#!/bin/bash
docker ps -l
read -p "請輸入你要進去的容器:" CNAME
#CNAME=$1
CPID=$(docker inspect --format "{{.State.Pid}}" $CNAME)
nsenter --target "$CPID" --mount --uts --ipc --net --pid
###所有殺死容器
docker kill $(docker ps -a -q)