[英]How to install Docker with another Debian package?
I have 2 images on Docker Registry, so my requirement is to create Debian package to pull those 2 images and run on the installed machine.我在 Docker Registry 上有 2 个镜像,所以我的要求是创建 Debian 包来提取这 2 个镜像并在已安装的机器上运行。 My problem is if I want to use Docker command, Docker should be installed in the given machine.我的问题是如果我想使用 Docker 命令,应该在给定的机器上安装 Docker。 So Docker install already, then we can use it.所以Docker已经安装好了,然后我们就可以使用它了。 Otherwise I have to install it when I install that Debian Package.否则,我必须在安装该 Debian 软件包时安装它。
My DEBIAN/control
file look like this,我的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
I added Docker
and docker
for Depends
time to time, but it didn't work.我不时地为Depends
添加了Docker
和docker
,但是没有用。 so I added below lines to the preinst
file,所以我在preinst
文件中添加了以下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
this line wasn't able to run. sudo apt install -y docker-ce
这一行无法运行。 It gave me below error.它给了我以下错误。
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
Yes I know this happens because I'm running sudo apt install my_package.deb
to install my package already, so cannot run another sudo apt install
command inside my package.是的,我知道发生这种情况是因为我正在运行sudo apt install my_package.deb
来安装我的包,所以无法在我的包中运行另一个sudo apt install
命令。 How can I sort it out this problem?我该如何解决这个问题? This should be one time process.这应该是一次性过程。
There is one possible way.有一种可能的方法。
Create one shell
script that is divided into two sections.创建一个分为两部分的shell
脚本。
docker
pre-requisites required.第一部分涵盖了所需的所有docker
先决条件。debian
package.第二部分介绍了自定义debian
包的安装命令。$ curl -s http://example.com/my_installation_script.sh | bash
$ cloud_provider_cli service_name get object_file | cat object_file | bash
$ curl -s https://gist.githubusercontent.com/long_url/shell_script.sh | bash
$ curl -s https://gist.githubusercontent.com/long_url/shell_script.sh | bash
You can get the mentioned url by clicking raw
option on github to download your shell script from github gist. $ curl -s https://gist.githubusercontent.com/long_url/shell_script.sh | bash
您可以通过单击 github 上的raw
选项来获取提到的 url,以从 github gist 下载您的 shell 脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.