Docker - debian 7 安装

本文详细介绍了如何在 Debian 7 操作系统上安装和配置 Docker,包括下载 Docker CE 的最新版,解决依赖问题,以及启动和验证 Docker 服务的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似iPhoneapp)。几乎没有性能开销,可以很容易地在机器和数据中心中运行。最重要的是,他们不依赖于任何语言、框架或包装系统。


root@linux:/home/docker# uname -a

Linux linux 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64GNU/Linux


Docker安装


如果你想安装最新版本的docker,首先,检查你的APT系统能够处理httpsurl:如果你的主机不存在/usr/lib/apt/methods/https文件,请先安装apt-transport-https


root@linux:/home/docker# apt-getinstall apt-transport-https

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following NEW packages will beinstalled:

apt-transport-https

0 upgraded, 1 newly installed, 0 toremove and 22 not upgraded.

Need to get 109 kB of archives.

After this operation, 166 kB ofadditional disk space will be used.

Get:1 http://http.debian.net/debian/wheezy/main apt-transport-https amd64 0.9.7.9+deb7u2 [109 kB]

Fetched 109 kB in 3s (29.0 kB/s)

Selecting previously unselectedpackage apt-transport-https.

(Reading database ... 142313 filesand directories currently installed.)

Unpacking apt-transport-https (from.../apt-transport-https_0.9.7.9+deb7u2_amd64.deb) ...

Setting up apt-transport-https (0.9.7.9+deb7u2) ...


然后,添加docker镜像秘钥到你的本地秘钥库.

root@linux:/home/docker# apt-key adv--keyserver hkp://keyserver.ubuntu.com:80 --recv-keys36A1D7869245C8950F966E92D8576A8BA88D21E9

Executing: gpg--ignore-time-conflict --no-options --no-default-keyring--secret-keyring /tmp/tmp.1kCuytnVeI --trustdb-name/etc/apt//trustdb.gpg --keyring /etc/apt/trusted.gpg--primary-keyring /etc/apt/trusted.gpg --keyring/etc/apt/trusted.gpg.d//debian-archive-squeeze-automatic.gpg--keyring/etc/apt/trusted.gpg.d//debian-archive-squeeze-stable.gpg--keyring/etc/apt/trusted.gpg.d//debian-archive-wheezy-automatic.gpg--keyring /etc/apt/trusted.gpg.d//debian-archive-wheezy-stable.gpg--keyserver hkp://keyserver.ubuntu.com:80 --recv-keys36A1D7869245C8950F966E92D8576A8BA88D21E9

gpg: requesting key A88D21E9 fromhkp server keyserver.ubuntu.com

gpg: key A88D21E9: public key"Docker Release Tool (releasedocker) <docker@dotcloud.com>"imported

gpg: Total number processed: 1

gpg: imported: 1 (RSA: 1)


添加Docker镜像添加你的apt软件源,更新和安装lxc-docker包。你可能会受到一个警告信息,这个包不可信,输入yes继续安装。

root@linux:/home/docker# echo debhttps://get.docker.io/ubuntu docker main >/etc/apt/sources.list.d/docker.list

root@linux:/home/docker# cat/etc/apt/sources.list.d/docker.list

deb https://get.docker.io/ubuntu docker main


提示:这还有一个简单的curl脚本来协助你完成这一工作。

$curl -s https://get.docker.io/ubuntu/ | sudo sh


root@linux:/home/docker# apt-getupdate

Hit http://ftp.debian.orgwheezy-updates Release.gpg

Hit http://security.debian.orgwheezy/updates Release.gpg

Hit http://ftp.debian.orgwheezy-updates Release

Hit http://security.debian.orgwheezy/updates Release

Hit http://ftp.debian.orgwheezy-updates/main Sources

Get:1 https://get.docker.io dockerRelease.gpg [473 B]

Hit http://security.debian.orgwheezy/updates/main Sources

Hit http://http.debian.net wheezyRelease.gpg

Hit http://ftp.debian.orgwheezy-updates/contrib Sources

Hit http://security.debian.orgwheezy/updates/main amd64 Packages

Get:2 https://get.docker.io dockerRelease [1,525 B]

Get:3 http://ftp.debian.orgwheezy-updates/main amd64 Packages/DiffIndex [1,471 B]

Get:4 http://http.debian.netwheezy-updates Release.gpg [836 B]

Hit http://security.debian.orgwheezy/updates/main Translation-en

Hit http://ftp.debian.orgwheezy-updates/contrib amd64 Packages

Get:5 https://get.docker.iodocker/main amd64 Packages [4,532 B]

Hit http://ftp.debian.orgwheezy-updates/contrib Translation-en

Hit http://http.debian.net wheezyRelease

Get:6 http://ftp.debian.orgwheezy-updates/main Translation-en/DiffIndex [919 B]

Get:7 http://http.debian.netwheezy-updates Release [124 kB]

Hit http://http.debian.netwheezy/main Sources

Hit http://http.debian.netwheezy/main amd64 Packages

Hit http://http.debian.netwheezy/main Translation-en

Get:8 http://http.debian.netwheezy-updates/main Sources [4,478 B]

Get:9 http://http.debian.netwheezy-updates/main amd64 Packages/DiffIndex [1,471 B]

Get:10 http://http.debian.netwheezy-updates/main Translation-en/DiffIndex [919 B]

Ign https://get.docker.iodocker/main Translation-en_US

Ign https://get.docker.iodocker/main Translation-en

Fetched 140 kB in 15s (8,899 B/s)

Reading package lists... Done


注意:Ubuntu(Debain)包含一个特别陈旧的KED3/GNOME2包叫docker,所以我们把这个包叫docker.io

root@linux:/home/docker# apt-cachesearch docker

karbon - vector graphics applicationfor the Calligra Suite

docker - System tray for KDE3/GNOME2docklet applications

kdocker - lets you dock anyapplication into the system tray

lxc-docker - Linux containerruntime

lxc-docker-0.10.0 - Linux containerruntime

lxc-docker-0.11.0 - Linux containerruntime

lxc-docker-0.11.1 - Linux containerruntime

lxc-docker-0.12.0 - Linux containerruntime

lxc-docker-0.5.3 - lxc-docker is aLinux container runtime

lxc-docker-0.6.0 - lxc-docker is aLinux container runtime

lxc-docker-0.6.1 - lxc-docker is aLinux container runtime

lxc-docker-0.6.2 - lxc-docker is aLinux container runtime

lxc-docker-0.6.3 - lxc-docker is aLinux container runtime

lxc-docker-0.6.4 - lxc-docker is aLinux container runtime

lxc-docker-0.6.5 - lxc-docker is aLinux container runtime

lxc-docker-0.6.6 - lxc-docker is aLinux container runtime

lxc-docker-0.6.7 - Linux containerruntime

lxc-docker-0.7.0 - Linux containerruntime

lxc-docker-0.7.1 - Linux containerruntime

lxc-docker-0.7.2 - Linux containerruntime

lxc-docker-0.7.3 - Linux containerruntime

lxc-docker-0.7.4 - Linux containerruntime

lxc-docker-0.7.5 - Linux containerruntime

lxc-docker-0.7.6 - Linux containerruntime

lxc-docker-0.8.0 - Linux containerruntime

lxc-docker-0.8.1 - Linux containerruntime

lxc-docker-0.9.0 - Linux containerruntime

lxc-docker-0.9.1 - Linux containerruntime

lxc-docker-1.0.0 - Linux containerruntime

lxc-docker-1.0.1 - Linux containerruntime

lxc-docker-1.1.0 - Linux containerruntime

lxc-docker-1.1.1 - Linux containerruntime

lxc-docker-1.1.2 - Linux container runtime


root@linux:/home/docker# apt-getinstall lxc-docker

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following extra packages will beinstalled:

aufs-tools git git-manliberror-perl lxc-docker-1.1.2 rsync

Suggested packages:

git-daemon-run git-daemon-sysvinitgit-doc git-el git-arch git-cvs git-svn git-email git-gui

gitk gitweb openssh-server

Recommended packages:

cgroupfs-mount cgroup-lite

The following NEW packages will beinstalled:

aufs-tools git git-manliberror-perl lxc-docker lxc-docker-1.1.2 rsync

0 upgraded, 7 newly installed, 0 toremove and 22 not upgraded.

Need to get 12.7 MB of archives.

After this operation, 33.2 MB ofadditional disk space will be used.

Do you want to continue [Y/n]? Y

Get:1 https://get.docker.io/ubuntu/docker/main lxc-docker-1.1.2 amd64 1.1.2 [4,426 kB]

Get:2 http://http.debian.net/debian/wheezy/main aufs-tools amd64 1:3.0+20120411-2 [91.9 kB]

Get:3 http://http.debian.net/debian/wheezy/main liberror-perl all 0.17-1 [23.6 kB]

Get:4 http://http.debian.net/debian/wheezy/main git-man all 1:1.7.10.4-1+wheezy1 [1,074 kB]

Get:5 https://get.docker.io/ubuntu/docker/main lxc-docker amd64 1.1.2 [1,786 B]

Get:6 http://http.debian.net/debian/wheezy/main git amd64 1:1.7.10.4-1+wheezy1 [6,683 kB]

Get:7 http://http.debian.net/debian/wheezy/main rsync amd64 3.0.9-4 [369 kB]

Fetched 12.7 MB in 46s (271 kB/s)

Selecting previously unselectedpackage aufs-tools.

(Reading database ... 142319 filesand directories currently installed.)

Unpacking aufs-tools (from.../aufs-tools_1%3a3.0+20120411-2_amd64.deb) ...

Selecting previously unselectedpackage liberror-perl.

Unpacking liberror-perl (from.../liberror-perl_0.17-1_all.deb) ...

Selecting previously unselectedpackage git-man.

Unpacking git-man (from.../git-man_1%3a1.7.10.4-1+wheezy1_all.deb) ...

Selecting previously unselectedpackage git.

Unpacking git (from.../git_1%3a1.7.10.4-1+wheezy1_amd64.deb) ...

Selecting previously unselectedpackage rsync.

Unpacking rsync (from.../rsync_3.0.9-4_amd64.deb) ...

Selecting previously unselectedpackage lxc-docker-1.1.2.

Unpacking lxc-docker-1.1.2 (from.../lxc-docker-1.1.2_1.1.2_amd64.deb) ...

Selecting previously unselectedpackage lxc-docker.

Unpacking lxc-docker (from.../lxc-docker_1.1.2_amd64.deb) ...

Processing triggers for man-db ...

Setting up aufs-tools(1:3.0+20120411-2) ...

Setting up liberror-perl (0.17-1)...

Setting up git-man(1:1.7.10.4-1+wheezy1) ...

Setting up git(1:1.7.10.4-1+wheezy1) ...

Setting up rsync (3.0.9-4) ...

update-rc.d: using dependency basedboot sequencing

Setting up lxc-docker-1.1.2 (1.1.2)...

[ ok ] Starting Docker: docker.

Setting up lxc-docker (1.1.2) ...


root@linux:/home/docker# docker
Usage: docker [OPTIONS] COMMAND [arg...]
 -H=[unix:///var/run/docker.sock]: tcp://host:port to bind/connect to or unix://path/to/socket to use

A self-sufficient runtime for linux containers.

Commands:
    attach    Attach to a running container
    build     Build an image from a Dockerfile
    commit    Create a new image from a container's changes
    cp        Copy files/folders from a container's filesystem to the host path
    diff      Inspect changes on a container's filesystem
    events    Get real time events from the server
    export    Stream the contents of a container as a tar archive
    history   Show the history of an image
    images    List images
    import    Create a new filesystem image from the contents of a tarball
    info      Display system-wide information
    inspect   Return low-level information on a container
    kill      Kill a running container
    load      Load an image from a tar archive
    login     Register or log in to the Docker registry server
    logs      Fetch the logs of a container
    port      Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
    pause     Pause all processes within a container
    ps        List containers
    pull      Pull an image or a repository from a Docker registry server
    push      Push an image or a repository to a Docker registry server
    restart   Restart a running container
    rm        Remove one or more containers
    rmi       Remove one or more images
    run       Run a command in a new container
    save      Save an image to a tar archive
    search    Search for an image on the Docker Hub
    start     Start a stopped container
    stop      Stop a running container
    tag       Tag an image into a repository
    top       Lookup the running processes of a container
    unpause   Unpause a paused container
    version   Show the Docker version information
    wait      Block until a container stops, then print its exit code


查看已安装镜像

docker@linux:~$ docker images  
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE


搜索镜像

docker@linux:~$ docker search debian:wheezy
NAME      DESCRIPTION                          STARS     OFFICIAL   AUTOMATED
debian    (Semi) Official Debian base image.   113       [OK]  


下载镜像

docker@linux:~$ docker pull debian:wheezy
Pulling repository debian
c1eec48018ed: Download complete  
511136ea3c5a: Download complete  
a9d9abc9a8a0: Download complete

安装完镜像后,显示如下:

docker@linux:~$ docker images  
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
debian              wheezy              c1eec48018ed        9 days ago          85.18 MB


使用镜像

docker@linux:~$ docker run -t -i debian:wheezy /bin/bash
root@6a641a2ac89d:/#


root@6a641a2ac89d:/# uname -a       
Linux 6a641a2ac89d 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux
root@6a641a2ac89d:/# apt-get update
Get:1 http://security.debian.org wheezy/updates Release.gpg [836 B]                                  
Get:2 http://http.debian.net wheezy Release.gpg [1655 B]                                                
Get:3 http://security.debian.org wheezy/updates Release [102 kB]  
Get:4 http://http.debian.net wheezy-updates Release.gpg [836 B]          
Get:5 http://http.debian.net wheezy Release [168 kB]                                  
Get:6 http://http.debian.net wheezy-updates Release [124 kB]                      
Get:7 http://security.debian.org wheezy/updates/main amd64 Packages [262 kB]          
Get:8 http://http.debian.net wheezy/main amd64 Packages [7626 kB]                                                     
Get:9 http://http.debian.net wheezy-updates/main amd64 Packages [6116 B]                                              
Fetched 8292 kB in 22s (362 kB/s)                                                                                                                   
Reading package lists... Done
root@6a641a2ac89d:/# apt-get install tree
Reading package lists... Done
Building dependency tree        
Reading state information... Done
The following NEW packages will be installed:
  tree
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 43.3 kB of archives.
After this operation, 112 kB of additional disk space will be used.
Get:1 http://http.debian.net/debian/ wheezy/main tree amd64 1.6.0-1 [43.3 kB]
Fetched 43.3 kB in 1s (35.2 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package tree.
(Reading database ... 6701 files and directories currently installed.)
Unpacking tree (from .../tree_1.6.0-1_amd64.deb) ...
Setting up tree (1.6.0-1) ...
root@6a641a2ac89d:/# exit
exit


查看现有容器

docker@linux:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
6a641a2ac89d        debian:wheezy       /bin/bash           3 minutes ago       Exited (0) 25 seconds ago                       suspicious_mayer   


提交容器

docker@linux:~$ docker commit -a "nixawk" -m "apt-get update" suspicious_mayer debian:update
aa507fc55e1f2add272ce06e1e8feefc38db50ccdab57d47df6ad96fa59958ab
 
docker@linux:~$ docker images  
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
debian              update              aa507fc55e1f        48 seconds ago      94.02 MB
debian              wheezy              c1eec48018ed        9 days ago          85.18 MB

如果有docker.com帐号,可以将自己的镜像提交到hub里面.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值