Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 容器销毁前Docker git推送_Node.js_Git_Docker - Fatal编程技术网

Node.js 容器销毁前Docker git推送

Node.js 容器销毁前Docker git推送,node.js,git,docker,Node.js,Git,Docker,我已停靠一个节点项目。此项目生成文件 每当容器被销毁时,我都会丢失生成的所有文件。我正在考虑使用“SIGTERM”事件,并在容器即将销毁时进行git推送 在这种情况下,还有其他方法可以使用吗?您可以使用(请参阅)。它允许从容器访问主机文件系统,这意味着容器能够将文件存储在主机可用的目录中,即使它退出 对于您的情况,这意味着项目将使用容器本地的文件路径在某个文件夹中生成文件,而您仍将使用主机系统路径从外部看到更改。据我所知,您希望能够在销毁容器之前将文件保存在容器中。您有几种可能性: 在您的容器

我已停靠一个节点项目。此项目生成文件

每当容器被销毁时,我都会丢失生成的所有文件。我正在考虑使用“SIGTERM”事件,并在容器即将销毁时进行git推送

在这种情况下,还有其他方法可以使用吗?

您可以使用(请参阅)。它允许从容器访问主机文件系统,这意味着容器能够将文件存储在主机可用的目录中,即使它退出


对于您的情况,这意味着项目将使用容器本地的文件路径在某个文件夹中生成文件,而您仍将使用主机系统路径从外部看到更改。

据我所知,您希望能够在销毁容器之前将文件保存在容器中。您有几种可能性:

  • 在您的容器上-即使在容器被销毁后,您的数据仍然可用,并且可以装载到新容器上或备份到其他地方
  • 正如-所指出的,在容器销毁后,您的数据将在主机上可用
  • 使用销毁前备份主机上的数据

在我们的CI框架中,我们使用Jenkins和Docker。Jenkins启动一个Docker容器,然后在容器中运行一个命令来构建一些软件。软件构建完成后,容器内的构建脚本会发出一个命令,将容器作为映像提交并归档到Docker注册表。该映像包含所有临时文件和工具配置。这允许我们稍后从存档的映像重新创建一个容器,并使用所有依赖项和生成的文件重新运行测试

可以从容器内部运行以下脚本:

#!/usr/bin/env bash
set -ex
# The docker registry should be located at a hostname:port address. (see push ref link below)
REGISTRY=TESTRACK:5000
TAG=${2}
CONTAINER_NAME=${1}

function get-container-id() {
    # When executed from within a docker container, the kernel cgroup file contains a control group for docker processes
    # The container id of the current container (from within that container) can be fetched this way.
    cat /proc/self/cgroup | grep "cpuset:/docker" | sed 's/\([0-9]\+\):cpuset:\/docker\///g'
    # Below, using head, is less reliable; the docker line is not always the first line in the cgroup
    # head -1 /proc/self/cgroup | cut -d/ -f3
}
CONTAINER_ID=$(get-container-id)
if [ -z ${CONTAINER_ID} ]; then
    echo "Error. Did not find a docker container value!"
    exit 1
fi
# https://docs.docker.com/engine/reference/commandline/commit/#examples

docker commit ${CONTAINER_ID} ${REGISTRY}/${CONTAINER_NAME}:$TAG
docker tag ${REGISTRY}/${CONTAINER_NAME}:$TAG ${REGISTRY}/${CONTAINER_NAME}:latest

#remove existing images without tags
OLD=`docker images -f "reference=TESTRACK-1:5000/$CONTAINER_NAME" -f "dangling=true" -q`

if [ -n "${OLD}" ]; then
    docker rmi -f ${OLD} || true
fi


# https://docs.docker.com/engine/reference/commandline/push/
#do not show push progress
docker push ${REGISTRY}/${CONTAINER_NAME}:$TAG &> push_result_tag.txt
docker push ${REGISTRY}/${CONTAINER_NAME}:latest &> push_result.txt
请注意,如果容器有权访问Docker守护进程,则只能在容器内运行此脚本。因此,您应该启动一个可以访问docker守护进程套接字的容器

  -v /var/run/docker.sock:/var/run/docker.sock

可以将绑定挂载添加到本地文件系统,然后在方便的时候推送。