首页 > 解决方案 > 在 Docker 中堆栈 pkgdb

问题描述

我有一个 Dockerfile,它使用全局项目配置安装 Stack,并且还stack install为一堆东西运行,所以在 Docker 映像中,我们stack在包数据库中还有一些包。

所以当我在一个正在运行的图像容器的 bash 提示符下,我看到

$ stack --version
Version 2.5.1, Git revision d6ab861544918185236cf826cb2028abb266d6d5 x86_64 hpack-0.33.0
$ stack exec ghc-pkg list
/opt/stack/programs/x86_64-linux/ghc-tinfo6-8.8.4/lib/ghc-8.8.4/package.conf.d
    Cabal-3.0.1.0
    array-0.5.4.0
    base-4.13.0.0
...
/opt/stack/snapshots/x86_64-linux-tinfo6/fffebb3fddcd52e7f38de3e253571498d665f4223658a7bafc9d5035b02e4ef3/8.8.4/pkgdb
    Boolean-0.2.4
...
/opt/stack/global-project/.stack-work/install/x86_64-linux-tinfo6/fffebb3fddcd52e7f38de3e253571498d665f4223658a7bafc9d5035b02e4ef3/8.8.4/pkgdb
    ghc-parser-0.2.2.0
    hvega-0.11.0.0
...

然后我安装一个新包vinyl

$ stack install vinyl
vinyl> configure
vinyl> Configuring vinyl-0.13.0...
vinyl> build
...
vinyl> copy/register
vinyl> Installing library in /opt/stack/snapshots/x86_64-linux-tinfo6/1d59f4b6093ea66bb0acc2d4f8757c137c4f3937b8a5131f44a85db5db236e4e/8.8.4/lib/x86_64-linux-ghc-8.8.4/vinyl-0.13.0-22RZxwfYh3i37XmCDd1atp

但是vinyl已安装在具有不同哈希的快照数据库中,当我尝试使用它时,它不存在。

$ stack repl

Note: No local targets specified, so a plain ghci will be started with no package hiding or package options.
      
      You are using snapshot: lts-16.23
      
      If you want to use package hiding and options, then you can try one of the following:
      
      * If you want to start a different project configuration than /opt/stack/global-project/stack.yaml, then you can use
        stack init to create a new stack.yaml for the packages in the current directory. 
        
      * If you want to use the project configuration
        at /opt/stack/global-project/stack.yaml, then you can add to its 'packages' field.
      
Configuring GHCi with the following packages: 
GHCi, version 8.8.4: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /tmp/haskell-stack-ghci/2a3bbd58/ghci-script

Prelude> import Data.Vinyl

<no location info>: error:
    Could not find module ‘Data.Vinyl’
    Perhaps you meant Data.Kind (from base-4.13.0.0)

这是我想要的工作流程。我如何得到它?为什么在这种情况下 Stack 会安装到不同的快照数据库中?

标签: dockerhaskellhaskell-stack

解决方案


推荐阅读