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