安装Docker和下载images镜像和常用Docker命令
我的是centos7,也会6的方法:
$sudo yum install docker 直接yum安装contos7
使用centos6.5先获取epel源并
启动Docker,并注册开机服务 [root@iZ258c9w799Z ~]# sudo service docker start Redirecting to /bin/systemctl start docker.service [root@iZ258c9w799Z ~]# sudo chkconfig docker on Note: Forwarding request to 'systemctl enable docker.service'. Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
//查看是否启动
[root@iZ258c9w799Z ~]# ps -ef|grep docker
root 12584 1 0 11:33 ? 00:00:00 /bin/sh -c /usr/bin/docker-current daemon $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY 2>&1 | /usr/bin/forward-journald -tag docker
root 12585 12584 0 11:33 ? 00:00:00 /usr/bin/docker-current daemon --selinux-enabled
root 12586 12584 0 11:33 ? 00:00:00 /usr/bin/forward-journald -tag docker
root 12705 12448 0 11:34 pts/0 00:00:00 grep --color=auto docker
下载images镜像,现在下载基础的contos镜像:
[root@iZ258c9w799Z ~]# sudo docker pull centos:7 Trying to pull repository docker.io/library/centos ... 7: Pulling from library/centos 1544084fad81: Pull complete df0fc3863fbc: Pull complete a3d54b467fad: Pull complete a65193109361: Pull complete Digest: sha256:a9237ff42b09cc6f610bab60a36df913ef326178a92f3b61631331867178f982 Status: Downloaded newer image for docker.io/centos:7
查看是否安装成功:
[root@iZ258c9w799Z ~]# sudo docker images centos REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker.io/centos 7 a65193109361 2 weeks ago 196.7 MB
可以去docker下载你需要的镜像:https://hub.docker.com/
常用docker命令:
1、docker -h 帮助 2、获取镜像 sudo docker pull NAME[:TAG] sudo docker pull centos:latest 3、启动Container盒子 sudo docker run [OPTIONS] IMAGE [COMMAND] [ARG...] sudp docker run -t -i contos /bin/bash 4、查看镜像列表,列出本地的所有images sudo docker images [OPTIONS] [NAME] sudo docker images centos 5、查看容器列表,可看到我们创建过的所有container sudo docker ps [OPTIONS] sudo docker ps -a 6、删除镜像,从本地删除一个已经下载的镜像 sudo docker rmi IMAGE [IMAGE...] sudo docker rmi centos:latest 7、移除一个或多个容器实例 sudo docker rm [OPTIONS] CONTAINER [CONTAINER...] 移除所有微运行的容器 sudo docker rm sudo docker ps -aq 8、停止一个正在运行的容器 sudo docker kill [OPTIONS] CONTAINER [CONTAINNER...] sudo docker kill 026e 9、重启一个正在运行的容器 sudo docker restart [OPTIONS] contains[CONTAINER] sudo docker restart 026e 10、停止一个已经停止的容器 sudo docker start [OPTIONS] CONTAINER [CONTAINER..] sudo docker start 026e