这是我的 dockerfile for haskell:
FROM ubuntu:focal
RUN apt-get update && apt-get install -y build-essential curl
libffi-dev libffi7 libgmp-dev libgmp10
libncurses-dev libncurses5 libtinfo5
ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1
RUN sh -c "curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh"
RUN sh -c "curl -sSL https://get.haskellstack.org/ | sh"
即使它安装了ghcup,我也无法运行cabal
ghcup
.
怎么了?
即使在 bash 的 docker 容器中运行它也会说
[ Warn ] Cabal ver 3.4.0.0 already installed; if you really want to reinstall it, you may want to run 'ghcup rm cabal 3.4.0.0' first
但我不能发起阴谋集团或ghcup。
ghcup维护者在这里。
我建议在 Docker 中使用 ghcup,如下所示,这不需要弄乱 PATH:
FROM ubuntu:focal
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Berlin
# install dependencies
RUN
apt-get update -y &&
apt-get install -y --no-install-recommends
curl
libnuma-dev
zlib1g-dev
libgmp-dev
libgmp10
git
wget
lsb-release
software-properties-common
gnupg2
apt-transport-https
gcc
autoconf
automake
build-essential
# install gpg keys
ARG GPG_KEY=7784930957807690A66EBDBE3786C5262ECB4A3F
RUN gpg --batch --keyserver keys.openpgp.org --recv-keys $GPG_KEY
# install ghcup
RUN
curl https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup > /usr/bin/ghcup &&
chmod +x /usr/bin/ghcup &&
ghcup config set gpg-setting GPGStrict
ARG GHC=8.10.7
ARG CABAL=latest
# install GHC and cabal
RUN
ghcup -v install ghc --isolate /usr/local --force ${GHC} &&
ghcup -v install cabal --isolate /usr/local/bin --force ${CABAL}
您可以在此处阅读有关独立安装的信息。
您必须包含它们的PATH
路径才能被发现。 此外,我更喜欢使用bash
而不是sh
。
这个按预期工作,并注意将 ENV 变量声明为一些常见命令的两种不同方法:
FROM debian:stable-slim as build
# Install dependencies *You don't need all of them
RUN apt-get update -y
&& apt-get upgrade -y
&& apt-get install -y git jq bc make automake libnuma-dev
&& apt-get install -y rsync htop curl build-essential
&& apt-get install -y pkg-config libffi-dev libgmp-dev
&& apt-get install -y libssl-dev libtinfo-dev libsystemd-dev
&& apt-get install -y zlib1g-dev make g++ wget libncursesw5 libtool autoconf
&& apt-get clean
# Install ghcup
ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1
RUN bash -c "curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh"
RUN bash -c "curl -sSL https://get.haskellstack.org/ | sh"
# Add ghcup to PATH
ENV PATH=${PATH}:/root/.local/bin
ENV PATH=${PATH}:/root/.ghcup/bin
# Install cabal
RUN bash -c "ghcup upgrade"
RUN bash -c "ghcup install cabal 3.4.0.0"
RUN bash -c "ghcup set cabal 3.4.0.0"
# Install GHC
RUN bash -c "ghcup install ghc 8.10.4"
RUN bash -c "ghcup set ghc 8.10.4"
# Update Path to include Cabal and GHC exports
RUN bash -c "echo PATH="$HOME/.local/bin:$PATH" >> $HOME/.bashrc"
RUN bash -c "echo export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" >> $HOME/.bashrc"
RUN bash -c "source $HOME/.bashrc"
# Update cabal
RUN bash -c "cabal update"