问题描述
我在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
添加了Docker
和docker
,但是没有用。所以我在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
命令。我该如何解决这个问题?这应该是一次过程。
解决方法
有一种可能的方法。
创建一个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。