欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

Linux下Docker安装和使用教程

程序员文章站 2022-10-12 14:36:34
docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的、可移植的、自给自足的容器。 开发者在笔记本上编译测试通过的容器可以批量地在生产环境中部署,包括vm...

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镜像的容器(虚拟

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

出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

以上所述是小编给大家介绍的linux下docker安装和使用教程,希望对大家有所帮助