如何使用另一个Debian软件包安装Docker?

时间:2020-10-18 06:03:24

标签: linux ubuntu debian deb debian-packaging

我在Docker Registry上有2个映像,所以我的要求是创建Debian软件包以提取这2个映像并在已安装的计算机上运行。我的问题是,如果我想使用Docker命令,则应在给定机器上安装Docker。所以Docker已经安装好了,那么我们就可以使用它了。否则,在安装该Debian软件包时必须安装它。

我的target文件看起来像这样,

DEBIAN/control

我有时Package: bla-bla Version: 1.0 Architecture: all Priority: optional Maintainer: Bla Bla <bla.bla@bla.com> Installed-Size: 327000 Depends: unzip, curl, sqlite3, libsqlite3-dev, xdg-utils, apt-transport-https, ca-certificates, software-properties-common Homepage: https://www.example.com/ Section: Network, Databases, Web Servers, JavaScript, Python; Description: bla bla bla 添加了Dockerdocker,但是没有用。所以我在Depends文件中添加了以下几行

preinst

function check_whether_docker_installed() { service=docker is_running=$(ps aux | grep -v grep | grep -v "$0" | grep $service | wc -l | awk '{print $1}') if [ $is_running != "0" ]; then echo -e "\nservice $service is running" else initd=$(ls /etc/init.d/ | grep $service | wc -l | awk '{ print $1 }') if [ $initd = "1" ]; then startup=$(ls /etc/init.d/ | grep $service) echo -e "\nStarting Docker service" /etc/init.d/${startup} start echo "Docker service successfully started" else echo -e "\nService $service not yet installed, going to install it" sudo apt update curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" sudo apt update apt-cache policy docker-ce sudo apt install -y docker-ce sudo chmod +x /var/run/docker.sock echo "Docker successfully installed, let's check it again" check_whether_docker_installed fi fi } function download_and_install_docker_compose() { which docker-compose if [ $? -eq 0 ]; then echo -e "\ndocker-compose is installed!" else echo -e "\ndocker-compose is not installed!" sudo curl -L "https://github.com/docker/compose/releases/download/1.27.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose echo "docker-compose is successfully installed, let's check it again" download_and_install_docker_compose fi } check_whether_docker_installed download_and_install_docker_compose 此行无法运行。它给了我下面的错误。

sudo apt install -y docker-ce

是的,我知道发生这种情况是因为我正在运行E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it? chmod: cannot access '/var/run/docker.sock': No such file or directory 来安装我的软件包,因此无法在软件包中运行另一个sudo apt install my_package.deb命令。我该如何解决这个问题?这应该是一次过程。

1 个答案:

答案 0 :(得分:1)

有一种可能的方法。
创建一个shell脚本,该脚本分为两部分。

  • 第一部分介绍了所有docker先决条件。
  • 第二部分介绍了自定义debian软件包的安装命令。

要使所有这些都在一个命令中运行,有几个选项:

  • 将Shell脚本托管在http / https服务器上。确保要安装debian软件包的客户端计算机有权访问此http / https服务器。在您的客户端计算机上运行:
    $ curl -s http://example.com/my_installation_script.sh | bash
  • 如果要将此软件包安装在Cloud服务器上,则可以将shell脚本托管在Cloud Provider的对象存储(AWS:s3,Azure:Blob存储,GCP:Google Cloud Storage)中,并在客户端计算机上运行:
    $ cloud_provider_cli service_name get object_file | cat object_file | bash
  • 如果您可以公开发布脚本,可以将其作为要点写在Github_gist上并免费托管在该脚本中。在您的客户端计算机上:
    $ curl -s https://gist.githubusercontent.com/long_url/shell_script.sh | bash 您可以通过单击github上的raw选项以从github gist下载您的Shell脚本来获取所提到的URL。