Docker入门介绍

来源:互联网 发布:gs算法的matlab代码 编辑:程序博客网 时间:2024/06/05 11:47

CentOS Docker 安装1

1.检查Centos的版本

cat /etc/redhat-release

这里写图片描述

2.安装Docker

[root@localhost ~]# yum -y install docker

3.启动Docker服务

[root@localhost ~]# service docker start

4.运行hello-word 容器

[root@localhost ~]# docker run hello-world

Docker hello-world命令

[root@localhost ~]docker run ubuntu:15.10 /bin/echo “hello world”[root@localhost ~]docker run -it ubuntu:15.10 /bin/bash[root@localhost ~]docker run -d ubuntu:15.10 /bin/sh "while true;do echo hello world;sleep 1;done"[root@localhost ~]docker[root@localhost ~]docker <command> --help[root@localhost ~]docker run [-t] [-i] [-d] [-p] [-P] [--name] [--privileged=true] <images:version> <command> 

Docker容器命令

[root@localhost ~]docker start <Container ID or Container name>[root@localhost ~]docker ps[root@localhost ~]docker port <Container ID or Container name>[root@localhost ~]docker top <Container ID or Container name>[root@localhost ~]docker inspect <Container ID or Container name>[root@localhost ~]docker logs <Container ID or Container name>[root@localhost ~]docker stop <Container ID or Container name>[root@localhost ~]docker rm <Container ID or Container name>

Docker images 命令

[root@localhost ~]docker images[root@localhost ~]docker pull <images name:version>[root@localhost ~]docker search <images name>[root@localhost ~]docker rmi <images name:version>

更新镜像

[root@localhost ~]docker run -t -i ubuntu:15.10 /bin/bash[root@container id ~]apt-get update[root@container id ~]exit[root@localhost ~]docker commit -m "xxxx" -a "xxx" <container id> <image name:version> 

用Dockerfile2新生成镜像

[root@localhost ~]docker build -t <image name:version> <directory of Dockerfile>

Docker 应用实例

1.删除所有状态是Exited的容器

docker rm $(docker ps -a -q)

等价于

docker rm $(docker ps -a| grep "Exited"|awk '{print $1}')

2.后台启动insurtech_od_api镜像

docker run -d -p 192.168.100.136:8082:8081 --name insurtech --privileged=true -v /root/Docker/insurtech/log:/home/java/insurtech/log wangjunting/insurtech_od_api:0.1

  1. 1.http://www.runoob.com/docker/centos-docker-install.html ↩
  2. 2.见资源Dockerfile文件 ↩