Dokcer基础

本文详细介绍如何在CentOS7上安装配置Docker并使用DaoCloud镜像加速,包括安装Docker、设置镜像加速、拉取镜像、运行容器、端口映射及进入容器进行操作等步骤。
  1. centos7

  2. yum  -y install docker

  3. docker加速

1
curl -sSL https: //get .daocloud.io /daotools/set_mirror .sh | sh -s http: //224ac393 .m.daocloud.io

4.systemctl start  docker

1
2
3
4
5
6
7
8
9
10
[root@web01 ~] # systemctl  status  docker
● docker.service - Docker Application Container Engine
    Loaded: loaded ( /usr/lib/systemd/system/docker .service; enabled; vendor preset: disabled)
    Active: active (running) since Thu 2016-12-22 20:25:00 CST; 1 weeks 5 days ago
      Docs: http: //docs .docker.com
  Main PID: 799 (docker-current)
    Memory: 39.1M
    CGroup:  /system .slice /docker .service
            ├─  799  /usr/bin/docker-current  daemon --registry-mirror=http: //224ac393 .m.daocloud.io -- exec -opt native.cg...
            └─28516 docker-proxy -proto tcp -host-ip 59.110.25.215 -host-port 88 -container-ip 192.168.0.2 -container-p..

4.拉公共的镜像

1
2
3
4
5
6
7
8
docker  pull  centos
docker  pull  nginx
 
docker save  -o   nginx. tar .gz  nginx
docker save  -o   centos. tar .gz  centos
 
docker  load  --input nginx. tar .gz
docker  load  --input centos. tar .gz

5.启动一个nginx

1
2
3
4
5
docker  run -d   --name mynginx -p 59.110.25.215:88:80  nginx
说明:基于nginx镜像启动一个mynginx的容器  本机端口  88 端口对应容器 80 端口
浏览:
指定多个端口:
docker  run -d   --name mynginx -p 59.110.25.215:88:80  -p 59.110.25.215:443:443  nginx

wKioL1hrqa3BitYxAABggZmIqsU741.png-wh_50

6.查看对应的端口

1
2
3
4
5
docker port  mynginx
 
[root@web01 ~] # docker  port  mynginx
80 /tcp  -> 59.110.25.215:88
[root@web01 ~] #

7.进入docker容器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
  
# Use nsenter to access docker
  
docker_in(){
    NAME_ID=$1
   PID=$(docker inspect -f  "{{ .State.Pid }}"  $NAME_ID)
    nsenter -t$PID -m -u -i -n -p
}
  
docker_in $1
 
上述的脚本就是dockerin.sh
[root@web01 ~] # docker  ps -a 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
1f3d2f356995        nginx                "nginx -g 'daemon off"    18 minutes ago      Up 18 minutes       443 /tcp , 59.110.25.215:88->80 /tcp    mynginx
[root@web01 ~] # bash dockerin.sh   1f3d2f356995
root@1f3d2f356995:/ #

8.进入容器以后修改容器内部的东西

1
2
3
4
root@1f3d2f356995: /usr/share/nginx/html # echo "hello everyone"  > index.html 
root@1f3d2f356995: /usr/share/nginx/html # pwd
/usr/share/nginx/html
root@1f3d2f356995: /usr/share/nginx/html #

wKiom1hrq5Hgv7CmAAANRQ5N9IM801.png-wh_50










本文转自 小小三郎1 51CTO博客,原文链接:http://blog.51cto.com/wsxxsl/1888718,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值