2022
我们一起努力

debian安装docker教程(debian安装dockercompose)

本文目录:

  • 1、怎样在 debian 上装 docker
  • 2、Debian 9 国内环境下一键脚本安装Docker
  • 3、Debian11安装docker
  • 4、debian 8 怎么安装Docker
  • 5、Docker容器中安装Docker
  • 6、Debian安装Docker(国内源)

怎样在 debian 上装 docker

将Docker安装到CentOS或Fedora上

要将Docker安装到CentOS上,首先启用EPEL软件库,然后使用yum命令:

$ sudo yum install docker-io

$ sudo service docker start

$ sudo chkconfig docker on

要将Docker安装到Fedora上,使用下面这些命令:

$ sudo yum install docker-io

$ sudo systemctl start docker.service

$ sudo systemctl enable docker.service

将Docker安装到CentOS或Fedora上后,你需要将自己添加到docker群组,那样才能以非root用户的身份来运行Docker。为此,使用这个命令:

$ sudo usermod -a -G docker $USER

退出,重新登录,以激活群组变更。

至此,你应该能够以非特权用户的身份来运行docker命令了。

Docker的基本用法

你想启动一个新的Docker容器,就需要确定为容器使用哪个Docker映像。你可以搜索官方的Docker映像索引(),上面列出了公开可用的Docker映像。Docker索引包括:Docker团队管理的Linux基本映像(比如Ubuntu、Debian、Fedora和 CentOS),以及用户贡献的自定义映像(比如MySQL、Redis和WordPress)。

比如说,想在交互模式开启动一个Ubuntu容器,就要运行下面这个命令。容器一启动,最后的变量“/bin/bash”就在容器里面执行。

$ docker run -i -t ubuntu /bin/bash

你头一次运行上面这个命令时,它会通过网络下载可用的一个或多个Ubuntu docker映像,然后使用该映像,启动Docker容器。Ubuntu容器会立马启动,你会看到容器里面的控制台提示符。你可以访问容器沙箱里面的功能完备的Ubuntu操作系统。

如果你在提示符处键入“exit”,就会退出容器,容器会被停止。

想列出所有的容器(包括已停止的容器),运行这个命令:

$ docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

6a08a0b2bb4c ubuntu:14.04 /bin/bash About a minute ago Exit 0 cocky_ritchie

想在守护进程模式下重新启动某个已停止的容器:

$ docker start [container-id]

想移除某个已停止的容器:

$ docker rm [container-id]

想连接到后台运行的容器,以便查看容器或与之交互:

$ docker attach [container-id]

你可以随意定制某个运行中的容器(比如安装新软件)。如果你想把变更内容保存在当前容器中,先要在提示符处键入“exit”,退出容器的交互模式。然后使用这个命令,将已变更的映像保存为不同的映像:

$ docker commit [container-id] [new-image-name]

想获得你容器的容器ID,可以使用之前描述的“docker ps –a”命令。

一旦你已构建了像这样的新映像,就可以借助该映像启动一个新的容器了。

你还可以下载任何公开的容器映像(比如ubuntu,bowery/mysql),将它们保存到本地软件库中,如下所示。

$ docker pull [image name]

想查看所有本地下载/保存的容器映像:

$ docker images

你可以选择从哪个特定的映像来启动容器:

$ docker run -i -t [image-id] /bin/bash

想从本地软件库移除某个容器映像:

$ docker rmi [image-id]

将Docker安装到CentOS或Fedora上

要将Docker安装到CentOS上,首先启用EPEL软件库,然后使用yum命令:

$ sudo yum install docker-io

$ sudo service docker start

$ sudo chkconfig docker on

要将Docker安装到Fedora上,使用下面这些命令:

$ sudo yum install docker-io

$ sudo systemctl start docker.service

$ sudo systemctl enable docker.service

将Docker安装到CentOS或Fedora上后,你需要将自己添加到docker群组,那样才能以非root用户的身份来运行Docker。为此,使用这个命令:

$ sudo usermod -a -G docker $USER

退出,重新登录,以激活群组变更。

至此,你应该能够以非特权用户的身份来运行docker命令了。

Docker的基本用法

你想启动一个新的Docker容器,就需要确定为容器使用哪个Docker映像。你可以搜索官方的Docker映像索引(),上面列出了公开可用的Docker映像。Docker索引包括:Docker团队管理的Linux基本映像(比如Ubuntu、Debian、Fedora和 CentOS),以及用户贡献的自定义映像(比如MySQL、Redis和WordPress)。

比如说,想在交互模式开启动一个Ubuntu容器,就要运行下面这个命令。容器一启动,最后的变量“/bin/bash”就在容器里面执行。

$ docker run -i -t ubuntu /bin/bash

你头一次运行上面这个命令时,它会通过网络下载可用的一个或多个Ubuntu docker映像,然后使用该映像,启动Docker容器。Ubuntu容器会立马启动,你会看到容器里面的控制台提示符。你可以访问容器沙箱里面的功能完备的Ubuntu操作系统。

如果你在提示符处键入“exit”,就会退出容器,容器会被停止。

想列出所有的容器(包括已停止的容器),运行这个命令:

$ docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

6a08a0b2bb4c ubuntu:14.04 /bin/bash About a minute ago Exit 0 cocky_ritchie

想在守护进程模式下重新启动某个已停止的容器:

$ docker start [container-id]

想移除某个已停止的容器:

$ docker rm [container-id]

想连接到后台运行的容器,以便查看容器或与之交互:

$ docker attach [container-id]

你可以随意定制某个运行中的容器(比如安装新软件)。如果你想把变更内容保存在当前容器中,先要在提示符处键入“exit”,退出容器的交互模式。然后使用这个命令,将已变更的映像保存为不同的映像:

$ docker commit [container-id] [new-image-name]

想获得你容器的容器ID,可以使用之前描述的“docker ps –a”命令。

一旦你已构建了像这样的新映像,就可以借助该映像启动一个新的容器了。

你还可以下载任何公开的容器映像(比如ubuntu,bowery/mysql),将它们保存到本地软件库中,如下所示。

$ docker pull [image name]

想查看所有本地下载/保存的容器映像:

$ docker images

你可以选择从哪个特定的映像来启动容器:

$ docker run -i -t [image-id] /bin/bash

想从本地软件库移除某个容器映像:

$ docker rmi [image-id]

Debian 9 国内环境下一键脚本安装Docker

最近在学习kubernetes的架设,自然就需要安装很多Docker,但是安装操作系统、修改仓库、安装Docker这一路下来步骤太多,自己就用三脚猫功夫写了个脚本,脚本其实挺强大,我这入门的水平都可以写出可实际使用的效果。

因为技术比较入门,所以步骤非常繁琐,但实测确实有效。

Debian11安装docker

获取加速服务方法

需要将当前用户加入 docker 用户组,否则进行相关操作会提示没有权限,也不建议使用 root 身份来操作docker

至此,docker安装完成。

debian 8 怎么安装Docker

一般这类软件官网都有FAQ的。还有看官网的user guide

英文安装过程如下:

Debian

Docker is supported on the following versions of Debian:

Debian testing stretch (64-bit)

Debian 8.0 Jessie (64-bit)

Debian 7.7 Wheezy (64-bit) (backports required)

Note: If you previously installed Docker using APT, make sure you update your APT sources to the new APT repository.

Prerequisites

Docker requires a 64-bit installation regardless of your Debian version. Additionally, your kernel must be 3.10 at minimum. The latest 3.10 minor version or a newer maintained version are also acceptable.

Kernels older than 3.10 lack some of the features required to run Docker containers. These older versions are known to have bugs which cause data loss and frequently panic under certain conditions.

To check your current kernel version, open a terminal and use uname -r to display your kernel version:

$ uname -r

Additionally, for users of Debian Wheezy, backports must be available. To enable backports in Wheezy:

Log into your machine and open a terminal with sudo or root privileges.

Open the /etc/apt/sources.list.d/backports.list file in your favorite editor.

If the file doesn’t exist, create it.

Remove any existing entries.

Add an entry for backports on Debian Wheezy.

An example entry:

deb wheezy-backports main

Update package information:

$ apt-get update

Update your apt repository

Docker’s APT repository contains Docker 1.7.1 and higher. To set APT to use from the new repository:

If you haven’t already done so, log into your machine as a user with sudo or root privileges.

Open a terminal window.

Purge any older repositories.

$ apt-get purge “lxc-docker*”

$ apt-get purge “docker.io*”

Update package information, ensure that APT works with the https method, and that CA certificates are installed.

$ apt-get update

$ apt-get install apt-transport-https ca-certificates

Add the new GPG key.

$ apt-key adv –keyserver hkp://p80.pool.sks-keyservers.net:80 –recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Open the /etc/apt/sources.list.d/docker.list file in your favorite editor.

If the file doesn’t exist, create it.

Remove any existing entries.

Add an entry for your Debian operating system.

The possible entries are:

Note: Docker does not provide packages for all architectures. To install docker on a multi-architecture system, add an [arch=…] clause to the entry. Refer to the Debian Multiarch wiki for details.

On Debian Wheezy

deb debian-wheezy main

On Debian Jessie

deb debian-jessie main

On Debian Stretch/Sid

deb debian-stretch main

Save and close the file.

Update the APT package index.

$ apt-get update

Verify that APT is pulling from the right repository.

$ apt-cache policy docker-engine

From now on when you run apt-get upgrade, APT pulls from the new apt repository.

Install Docker

Before installing Docker, make sure you have set your APT repository correctly as described in the prerequisites.

Update the APT package index.

$ sudo apt-get update

Install Docker.

$ sudo apt-get install docker-engine

Start the docker daemon.

$ sudo service docker start

Verify docker is installed correctly.

$ sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message. Then, it exits.

Giving non-root access

The docker daemon always runs as the root user and the docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root, and so, by default, you can access it with sudo.

If you (or your Docker installer) create a Unix group called docker and add users to it, then the docker daemon will make the ownership of the Unix socket read/writable by the docker group when the daemon starts. The docker daemon must always run as the root user, but if you run the docker client as a user in thedocker group then you don’t need to add sudo to all the client commands. From Docker 0.9.0 you can use the -G flag to specify an alternative group.

Warning: The docker group (or the group specified with the -G flag) is root-equivalent; see Docker Daemon Attack Surface details.

Example:

# Add the docker group if it doesn’t already exist.

$ sudo groupadd docker

# Add the connected user “${USER}” to the docker group.

# Change the user name to match your preferred user.

# You may have to logout and log back in again for

# this to take effect.

$ sudo gpasswd -a ${USER} docker

# Restart the Docker daemon.

$ sudo service docker restart

Upgrade Docker

To install the latest version of Docker with apt-get:

$ apt-get upgrade docker-engine

Uninstall

To uninstall the Docker package:

$ sudo apt-get purge docker-engine

To uninstall the Docker package and dependencies that are no longer needed:

$ sudo apt-get autoremove –purge docker-engine

The above commands will not remove images, containers, volumes, or user created configuration files on your host. If you wish to delete all images, containers, and volumes run the following command:

$ rm -rf /var/lib/docker

You must delete the user created configuration files manually.

如果你用apt 请先更新apt 

docker 支持64位debain .内核最低必须是3.10的。

可以用 uname -r 命令查看系统和内核版本

Docker容器中安装Docker

最近用到Jenkins,使用了Docker来提供服务,但是在构建步骤中又希望能够使用Docker去生成镜像,因此需要实现在Docker容器中去安装Docker,其实也就是在特定的系统环境下安装Docker,但是实际操作中可能还会出现其他问题。

以Jenkins/Jenkins容器为例子。

进入jenkins容器:

一般安装前都需要知道当前系统信息,没有安装lsb-core,因此执行:

我在第一次查询时候也看不出来是用的哪个系统以及版本,猜测应该为Debian。

因为原来的配置的源速度太慢(无效?),因此执行apt-get update都会失败,所以无法去安装新的软件。所以需要先更改源配置,这个过程中我找到了不少配置信息,但是基本都因为key过期等原因不能够使用。这里推荐一个很好的网站,会每隔四小时发布Debian的源地址:

备份Linux的源配置文件:

修改源配置信息(因为没有安装vim,只能通过方式将地址写入文件)

然后安装vim,方便后面查看等操作。

编辑sources.list 文件,配置完整地址。

同样安装lsb-core,安装完成后可以使用lsb_release -a查看系统版本。

接下来就是安装Docker,这里我们已经知道是在Debian环境下安装Docker,可以参考菜鸟的步骤:

Debian安装Docker(国内源)

参考docker官方文档:

文章最后列出了使用国内源的安装步骤

老版本的Docker名为: docker, docker.io或者docker-engine(不存在)

在安装Docker之前首先需要设置仓库源。

5:20.10.8~3-0~debian-bullseye 为版本号

安装指定版本

【debian安装docker教程】的内容来源于互联网,如引用不当,请联系我们修改。

赞(0)
文章名称:《debian安装docker教程(debian安装dockercompose)》
文章链接:https://www.fzvps.com/39461.html
本站文章来源于互联网,如有侵权,请联系管理删除,本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

相关推荐

  • 暂无文章

评论 抢沙发

评论前必须登录!