如何使用其他 Debian 包安装 Docker?

如何使用其他 Debian 包安装 Docker?

我在 Docker Registry 上有 2 个镜像,所以我的要求是创建 Debian 包来提取这 2 个镜像并在已安装的机器上运行。我的问题是,如果我想使用 Docker 命令,Docker 应该安装在给定的机器上。所以 Docker 已经安装,然后我们可以使用它。否则,我必须在安装该 Debian 包时安装它。

我的DEBIAN/control文件如下所示,

Package: bla-bla
Version: 1.0
Architecture: all
Priority: optional
Maintainer: Bla Bla <[email protected]>
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

我时不时地添加和Docker,但没有用。所以我在文件中添加了以下几行,dockerDependspreinst

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安装我的包,所以无法sudo apt install在包内运行另一个命令。我该如何解决这个问题?这应该是一次性的过程。

答案1

为什么不直接将其添加docker.io到所需包的列表中?

Package: bla-bla
Version: 1.0
Architecture: all
Priority: optional
Maintainer: Bla Bla <[email protected]>
Installed-Size: 327000
Depends: docker.io, 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

这当然不是docker-ce,但您不能在脚本apt-get中使用DEBIAN/control。包依赖关系只能使用Depends选项来处理。

您也可以添加docker-ce到列表中,但如果未在本地系统中注册,Depends则包安装将失败。docker-ce

相关内容