docker入门1:安装和命令使用

1.在redhat上安装docker,需要kernel升级到3以上:
[root@rhel64-64bit ipv4]# uname -r
4.4.131-1.el6.elrepo.x86_64

2.在/etc/yum.repos.d下创建docke.repo:

[dockerrepo]  
name=Docker Repository  
baseurl=https://yum.dockerproject.org/repo/main/centos/6/  
enabled=1  
gpgcheck=0  
gpgkey=https://yum.dockerproject.org/gpg 

yum makecache
yum install docker-engine
yum update device-mapper

安装后查看:

[root@rhel64-64bit ipv4]# rpm -qa|grep docker
docker-engine-1.7.1-1.el6.x86_64

3.service docker start 启动docker服务
 or /etc/init.d/docker start

4.查看安装版本信息:

 [root@rhel64-64bit Desktop]# docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d
OS/Arch (server): linux/amd64

5.Docker守护进程会生成一个socket(/var/run/docker.sock)文件来进行本地进程通信,而不会监听任何端口,
  因此只能在本地使用docker客户端或者使用Docker API进行操作:

[root@rhel64-64bit ipv4]# netstat -pan|grep docker
unix  2      [ ACC ]     STREAM     LISTENING     252660 15608/docker        /var/run/docker.sock

若要允许远程访问,需:/etc/default/docker或/etc/sysconfig/docker加入:
DOCKER_OPTS="-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"
重启docker进程

或者命令启动的时候加入-H参数:
nohup docker -H tcp://127.0.0.1:2375 -d &
[root@rhel64-64bit ipv4]# jobs -l
[1]+ 21758 Running                 docker -H tcp://127.0.0.1:2375 -d &
客户端以ip访问:
[root@rhel64-64bit ~]# docker -H 127.0.0.1:2375 images
REPOSITORY                    TAG                 IMAGE ID            CREATED                  VIRTUAL SIZE
daocloud.io/library/tomcat    latest              8e956bfcc8a4        Less than a second ago   467.1 MB
jpress                        latest              fbd01889a1e3        4 hours ago              487.8 MB
通过openssl生成的证书加密实现的安全的远程访问:
https://docs.docker.com/engine/security/https/#create-a-ca-server-and-client-keys-with-openssl


6.基本命令:

   docker --help
   docker search --help 都可以使用--help查看命令参数
1>docker search mysql   搜索镜像
2>docker pull daocloud.io/library/tomcat  拉取镜像,如果没有写地址默认是registry是从官网hub.docker.com拉取
3>docker build -t artest:latest  Dockerfile   通过Dockerfile创建镜像,-t是给镜像的起名字标签
4>docker images  列出所有拉取过来的镜像
5>docker create image-name   创建容器
6>docker start container-id      启动容器,
7>docker run -p 8889:8080 -d tomcat  启动容器,docker run就是包含docker creat 和docker start两个命令过程
                                                               -p是主机和容器内端口映射,-d是启动容器放在后台运行
    docker run --net=host -it ubuntu bash
8>docker exec -it container-id bash    在运行的容器内执行命令
9>docker ps 列出正在运行的容器
     docker ps -a 列出所有容器包括停止的

oot@rhel64-64bit ~]# docker ps
CONTAINER ID    IMAGE     COMMAND                CREATED             STATUS              PORTS                  NAMES
17b426998b5b    yoyo      "nginx -g 'daemon of   8 hours ago         Up 14 minutes       0.0.0.0:9089->80/tcp   determined_lalande  

10>docker top container-id 查看容器内都有哪些进程
11>docker commit container-id  容器做了修改后可以commit成一个新的镜像以保存修改
      docker commit fa1f4e8f8af7 aryo:latest
12>docker stop container-id 停止运行的容器
13>docker rmi image-id 删除镜像
14>docker rm container-id 删除容器,container-id是一串字符,可以只写id前几个字符docker就可以识别
15>docker inspect container-id 容器的具体信息
16>命令使用例子:https://blog.csdn.net/aryoyo/article/details/80717716

7.hello world!

[root@rhel64-64bit ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED                  VIRTUAL SIZE
nginx                         latest              01133ef0d8b6        2 weeks ago              108.9 MB
ubuntu                        latest              023b41dce381        2 weeks ago              79.62 MB
hello-world                   latest              83f0de727d85        4 weeks ago              1.848 kB

root@rhel64-64bit ~]# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值