Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders from a container's filesystem to the host path
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Stream the contents of a container as a tar archive
history Show the history of an image
images List images
import Create a new filesystem image from the contents of a tarball
info Display system-wide information
inspect Return low-level information on a container
kill Kill a running container
load Load an image from a tar archive
login Register or log in to a Docker registry server
logout Log out from a Docker registry server
logs Fetch the logs of a container
port Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
pause Pause all processes within a container
ps List containers
pull Pull an image or a repository from a Docker registry server
push Push an image or a repository to a Docker registry server
restart Restart a running container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save an image to a tar archive
search Search for an image on the Docker Hub
start Start a stopped container
stop Stop a running container
tag Tag an image into a repository
top Lookup the running processes of a container
unpause Unpause a paused container
version Show the Docker version information
wait Block until a container stops, then print its exit code
[iyunv@localhost ~]# docker pull ubuntu:14.04
[iyunv@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 b7cf8f0d9e82 3 days ago 188.3 MB
2、基于镜像创建一个容器
1
2
3
4
[iyunv@localhost ~]# docker run -it ubuntu:14.04 /bin/bash
[iyunv@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
88b6a8dfae4e ubuntu:14.04 "/bin/bash" 3 minutes ago Up 3 minutes modest_yalow
3、进入容器安装ssh服务
1
2
3
4
5
6
7
8
9
root@88b6a8dfae4e:/# apt-get update && apt-get install -y openssh-server
root@0af7ccfd906e:/# echo 'root:redhat' | chpasswd
root@10dbbd22172d:/# mkdir /var/run/sshd
root@10dbbd22172d:/# sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
root@10dbbd22172d:/# sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
root@10dbbd22172d:/# exit
[iyunv@localhost ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
88b6a8dfae4e ubuntu:14.04 "/bin/bash" 10 minutes ago Exited (130) 18 seconds ago modest_yalow
4、构建一个ssh的镜像
1
2
3
4
5
6
[iyunv@localhost ~]# docker commit 88b6a8dfae4e zhengyas/ubuntu:sshd
3f2225df36ff67cbda098318e83128f3965758eba3e4609a094c172b0c3b03c4
[iyunv@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
zhengyas/ubuntu sshd 3f2225df36ff 21 seconds ago 251.1 MB
ubuntu 14.04 b7cf8f0d9e82 3 days ago 188.3 MB
5、基于新镜像运行一个ssh容器
1
2
3
4
5
[iyunv@localhost ~]# docker run -d -p 2222:22 zhengyas/ubuntu:sshd /usr/sbin/sshd -D
7ef47903cdb77ad9d98fd0dd3b102473d10ad3abea5311c030177db9ea9984c1
[iyunv@localhost ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ef47903cdb7 zhengyas/ubuntu:sshd "/usr/sbin/sshd -D" 4 seconds ago Up 4 seconds 0.0.0.0:2222->22/tcp hungry_ritchie
[iyunv@localhost ~]# ssh root192.168.0.104 -p 2222
ssh: Could not resolve hostname root192.168.0.104: Name or service not known
[iyunv@localhost ~]# ssh root@192.168.0.104 -p 2222
The authenticity of host '[192.168.0.104]:2222 ([192.168.0.104]:2222)' can't be established.
RSA key fingerprint is 0e:1e:4e:67:f3:4b:5a:c4:c2:f5:7b:e7:f0:2e:14:72.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.0.104]:2222' (RSA) to the list of known hosts. root@192.168.0.104's password:
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.2.0-61-generic x86_64)
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.