查看
docker info
[root@hadoop ~]# docker info
Containers: 0
Images: 37
Server Version: 1.9.1
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 37
Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.10.5-3.el6.x86_64
Operating System: <unknown>
CPUs: 1
Total Memory: 982.4 MiB
Name: hadoop
ID: GPVA:WPOI:422O:5YWJ:TZSN:ZY4P:HQHK:N7IO:BSED:AA6T:4G4B:BAD5
WARNING: No swap limit support
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
docker version
[root@hadoop ~]# docker version
Client:
Version: 1.9.1
API version: 1.21
Go version: go1.4.3
Git commit: a34a1d5
Built: Fri Nov 20 17:56:04 UTC 2015
OS/Arch: linux/amd64
Server:
Version: 1.9.1
API version: 1.21
Go version: go1.4.3
Git commit: a34a1d5
Built: Fri Nov 20 17:56:04 UTC 2015
OS/Arch: linux/amd64
-
docker search centos
搜索可用docker镜像 -
docker images
查看当前docker所有镜像 -
docker ps
列出所有运行中容器。-
docker ps -l
获得最后一个容器的id -
docker ps -a
查看所有的容器。
-
下载、导入导出
-
docker pull centos
下载镜像 -
cat centos.tar | docker import - centos6
Docker导入镜像 -
docker export id > cenos6.tar
Docker导出镜像
运行
-
docker run centos echo "hello word"
在docker容器中运行hello world!
[root@hadoop ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tomcat latest 4f17b211b1a3 12 days ago 557.6 MB
centos latest a1f992ad364a 3 weeks ago 203.5 MB
[root@hadoop ~]# docker run centos:latest echo "hello world"
hello world
查看容器中的文件
[root@hadoop ~]# docker run centos:latest cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
[root@hadoop ~]#
-
docker run centos yum install ntpdate
在容器中安装ntpdate的程序 -
docker run -d centos:v1 /bin/bash
-d表示在后台启动,以daemon方式启动。 -
docker run -i -t centos /bin/bash
在容器里启动一个/bin/bash shell
环境,可以登录进入操作,其中-t 表示打开一个终端的意思,-i表示可以交互输入。 -
查看容器中centos的版本
[root@hadoop ~]# docker run -i -t centos:latest /bin/bash
[root@b48f8f1133f4 /]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@b48f8f1133f4 /]#
- 退出centos容器
[root@b48f8f1133f4 ssh]# exit
exit
[root@hadoop ~]#
- 解决在容器中无法启动服务的问题,报如下错误:
Failed to get D-Bus connection: Operation not permitted
[root@hadoop ~]# docker run -tdi --privileged centos:latest /usr/sbin/init
9d8bdd656f840a3fad3c93b133a5fd181400708d6f3341460b71b82457f20023
[root@hadoop ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9d8bdd656f84 centos:latest "/usr/sbin/init" 19 seconds ago Up 14 seconds backstabbing_goldberg
[root@hadoop ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9d8bdd656f84 centos:latest "/usr/sbin/init" 53 seconds ago Up 48 seconds backstabbing_goldberg
[root@hadoop ~]# docker exec -it 9d8bdd656f84 /bin/bash
[root@9d8bdd656f84 /]# ll
total 52
......
[root@9d8bdd656f84 /]# yum install -y openssh-server.x86_64
[root@9d8bdd656f84 /]# systemctl start sshd
[root@9d8bdd656f84 /]# ps aux|grep ssh
root 184 0.4 0.4 106000 4072 ? Ss 17:53 0:00 /usr/sbin/sshd -D
root 186 0.0 0.0 9048 664 ? S+ 17:53 0:00 grep --color=auto ssh
-
docker run -d -p 80:80 -p 8022:22 centos:v2
解析:-p指定容器启动后docker上运行的端口映射及容器里运行的端口,80:80,第一个80表示docker系统上的80,第二个80表示docker虚拟机里面的端口。用户默认访问本机80端口,自动映射到容器里面的80端口。 -
docker exec -it id /bin/bash
-
docker commit 2313132 centos:v1
提交修改的容器,2313132 为容器id
关闭和删除
-
docker stop id
关闭容器 -
docker start id
启动某个容器 -
docker rm id
删除容器 -
docker rmi images
删除镜像
网友评论