阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下Docker安装和使用

109次阅读
没有评论

共计 4883 个字符,预计需要花费 13 分钟才能阅读完成。

Docker 是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的、可移植的、自给自足的容器。
开发者在笔记本上编译测试通过的容器可以批量地在生产环境中部署,包括 VMs(虚拟机)、bare metal、OpenStack 集群和其他的基础应用平台。
Docker 的源代码全部是用 Go 语言写的。
 
一、基础环境
1、角色、ip、版本、内核
serverA 10.1.10.236 3.16.0-4-amd64 8.1 docket
docket 1.6.2
 
二、安装 docter
1、添加源
echo “deb http://http.debian.net/debian jessie-backports main” >> /etc/apt/sources.list
 
2、更新源
apt-get update
 
3、安装 docker.io 包
apt-get install docker.io
Reading package lists… Done
Building dependency tree     
Reading state information… Done
The following extra packages will be installed:
  aufs-tools cgroupfs-mount git git-man libapparmor1 liberror-perl libnih-dbus1 libnih1 makedev mountall plymouth
Suggested packages:
  btrfs-tools debootstrap lxc rinse git-daemon-run git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn desktop-base
  plymouth-themes
The following NEW packages will be installed:
  aufs-tools cgroupfs-mount docker.io git git-man libapparmor1 liberror-perl libnih-dbus1 libnih1 makedev mountall plymouth
0 upgraded, 12 newly installed, 0 to remove and 54 not upgraded.
Need to get 9,986 kB of archives.
After this operation, 47.2 MB of additional disk space will be used.
Do you want to continue? [Y/n]
 
4、查看版本
docker –version
Docker version 1.6.2, build 7c8fca2
 
5、启动服务
/etc/init.d/docker start
[ok] Starting docker (via systemctl): docker.service.
 
6、拉取 debian 和 CentOS 镜像
1) 拉取 debian 镜像
docker pull debian
latest: Pulling from debian
843e2bded498: Pull complete
8c00acfb0175: Pull complete
debian:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:d9168a2c1889b4c9d44952a23065c29b0656237909d618328275f42065602354
Status: Downloaded newer image for debian:latest
2) 拉取 centos 镜像
docker pull centos
Pulling repository centos
0f73ae75014f: Download complete
47d44cb6f252: Download complete
f6f39725d938: Download complete
f9a8cbc8dd13: Download complete
f37e6a610a37: Download complete
Status: Downloaded newer image for centos:latest
 
7、查看镜像
docker images
REPOSITORY          TAG                IMAGE ID            CREATED            VIRTUAL SIZE
debian              latest              8c00acfb0175        3 weeks ago        125.2 MB
centos              latest              0f73ae75014f        3 weeks ago        172.3 MB
 
8、运行名为 debian 镜像的容器(虚拟出 1 个 debian 系统)
1) 运行 debian 镜像的容器
docker run -i -t debian
2) 查看版本
root@10.1.10.236:~# docker run debian cat /etc/debian_version
8.2
3) 查看 IP(是 dhcp 获得 每次获得都不一样)
root@10.1.10.236:~# docker run debian ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
24: eth0: <NO-CARRIER,BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:ac:11:00:0b brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.11/16 scope global eth0
      valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe11:b/64 scope link tentative
      valid_lft forever preferred_lft forever
4)查看内核     
root@10.1.10.236:~# docker run debian uname -r
3.16.0-4-amd64
5)查看硬盘分区情况
root@10.1.10.236:~# docker run -i -t debian df -Th
Filesystem    Type  Size  Used Avail Use% Mounted on
none          aufs  9.1G  1.6G  7.1G  18% /
tmpfs          tmpfs  115M    0  115M  0% /dev
shm            tmpfs  64M    0  64M  0% /dev/shm
/dev/sda1      ext4  9.1G  1.6G  7.1G  18% /etc/hosts
 
9、运行名为 centos 镜像的容器(虚拟出 1 个 centos 系统)
1) 运行 centos 镜像的容器
docker run -i -t centos
2) 查看版本
root@10.1.10.236:~# docker run centos cat /etc/RedHat-release
CentOS Linux release 7.1.1503 (Core)
3) 查看内核
root@10.1.10.236:~# docker run centos uname -r
3.16.0-4-amd64
4) 查看 ip
root@10.1.10.236:~# docker run centos ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
46: eth0: <NO-CARRIER,BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state DOWN
    link/ether 02:42:ac:11:00:16 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.22/16 scope global eth0
      valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe11:16/64 scope link tentative
      valid_lft forever preferred_lft forever
5)查看硬盘分区情况
root@10.1.10.236:~# docker run centos df -Th
Filesystem    Type    Size  Used Avail Use% Mounted on
rootfs        rootfs  9.1G  1.6G  7.1G  18% /
none          aufs    9.1G  1.6G  7.1G  18% /
tmpfs          tmpfs  115M    0  115M  0% /dev
shm            tmpfs    64M    0  64M  0% /dev/shm
/dev/sda1      ext4    9.1G  1.6G  7.1G  18% /etc/hosts
tmpfs          tmpfs  115M    0  115M  0% /proc/kcore
tmpfs          tmpfs  115M    0  115M  0% /proc/timer_stats

更多 Docker 相关教程见以下内容

Docker 安装应用(CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm 

Ubuntu 14.04 安装 Docker  http://www.linuxidc.com/linux/2014-08/105656.htm 

Ubuntu 使用 VNC 运行基于 Docker 的桌面系统  http://www.linuxidc.com/Linux/2015-08/121170.htm

阿里云 CentOS 6.5 模板上安装 Docker http://www.linuxidc.com/Linux/2014-11/109107.htm 

Ubuntu 15.04 下安装 Docker  http://www.linuxidc.com/Linux/2015-07/120444.htm 

在 Ubuntu Trusty 14.04 (LTS) (64-bit)安装 Docker http://www.linuxidc.com/Linux/2014-10/108184.htm 

在 Ubuntu 15.04 上如何安装 Docker 及基本用法 http://www.linuxidc.com/Linux/2015-09/122885.htm

Docker 的详细介绍:请点这里
Docker 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-10/123770.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4883字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中