我需要设置环境变量,通常我们这样做
source script.sh
Run Code Online (Sandbox Code Playgroud)
但是现在,我在启动过程中自动化它,它看起来像默认情况下使用shshell启动.如何获取此脚本sh?
我正在尝试基于public continuumio/anaconda3容器设置一个简单的docker镜像(我对docker很新,所以请纠正我可能的错误观念).
的Dockerfile:
FROM continuumio/anaconda3:latest
# update conda and setup environment
RUN conda update conda -y \
&& conda env list \
&& conda create -n testenv pip -y \
&& source activate testenv \
&& conda env list
Run Code Online (Sandbox Code Playgroud)
从此构建和图像docker build -t test .以错误结束:
/bin/sh: 1: source: not found
Run Code Online (Sandbox Code Playgroud)
激活新虚拟环境时.
按照这个答案我试过:
FROM continuumio/anaconda3:latest
# update conda and setup environment
RUN conda update conda -y \
&& conda env list …Run Code Online (Sandbox Code Playgroud) 我有一个nvm定义的bash函数/root/.profile.docker build我在RUN步骤中调用它时未能找到该功能.
RUN apt-get install -y curl build-essential libssl-dev && \
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
RUN nvm install 0.12 && \
nvm alias default 0.12 && \
nvm use 0.12
Run Code Online (Sandbox Code Playgroud)
错误是
Step 5 : RUN nvm install 0.12
---> Running in b639c2bf60c0
/bin/sh: nvm: command not found
Run Code Online (Sandbox Code Playgroud)
我设法nvm通过包装来调用bash -ic,这将加载/root/.profile.
RUN bash -ic "nvm install 0.12" && \
bash -ic "nvm alias default 0.12" && \
bash …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建 docker 并安装 nvm
一些代码行
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.25.0/install.sh | bash
RUN source ~/.profile
Run Code Online (Sandbox Code Playgroud)
curl 运行成功,但在运行源代码时,出现以下错误
/bin/sh: 1: source: not found
The command '/bin/sh -c source ~/.profile' returned a non-zero code: 127
Run Code Online (Sandbox Code Playgroud) 我已经安装了一个 python 包,并根据需要进行了修改,并将其存储在 venv 文件夹中。我想使用:
RUN source venv/bin/activate
Run Code Online (Sandbox Code Playgroud)
在我的 Dockerfile 中(当然将其复制到容器中之后)可以解决我的问题,但对此答案的评论表明它不能。后来,我发现这篇文章展示了如何在 docker 容器内设置新的 venv,但没有回答我的问题。许多其他答案让我陷入了无休止的疯狂追逐,所以我决定在这里提问。希望一个好的答案能够解决我的问题,并为将来在 docker 容器中自定义 python 包时面临这个问题的人提供服务。
我的问题:
如何使用复制到 docker 容器中的 venv?
这是 Dockerfile 中的脚本。当我直接进入 docker 并手动运行命令时,它工作正常,但为什么不是来自 Dockerfile。
Dockerfile:
FROM ubuntu:16.04
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get update
RUN apt-get install -y build-essential libssl-dev
RUN apt-get install -y curl git sudo
RUN curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install_nvm.sh
RUN /bin/sh install_nvm.sh
RUN source ~/.profile
Run Code Online (Sandbox Code Playgroud)
错误:
消息:ttyname 失败:设备的 ioctl 不合适
我已经尝试了一些发现的解决方案,比如运行它,
RUN /bin/sh -c "source ~/.profile"还有一些但没有解决问题。
几个小时前我刚刚开始学习 docker,并尝试制作自己的 docker 镜像。当我尝试制作 Dockerfile 和 docker 映像时,收到此错误消息“/bin/sh: 1: source: not find”。
首先,我在 .env 文件中管理环境变量。每当我更改 env 文件时,我都会运行此命令 $source .env 并 go build 。然后去运行main.go。因此,我尝试设置我的 Dockerfile,RUN source.env,但出现了上面提到的错误。
我试过
我真的很感谢你的帮助!
编辑1]
FROM golang:latest
WORKDIR /go/src/todo_list
# RUN go mod init github.com/jiwanjeon/go-todolist
# RUN go get github.com/jinzhu/gorm
# RUN go get github.com/lib/pq
# RUN go get github.com/gorilla/mux
# RUN go get github.com/stretchr/testify
# RUN go get github.com/jinzhu/gorm/dialects/postgres
# source …Run Code Online (Sandbox Code Playgroud) 我有一个定义Ruby on Rails堆栈的Dockerfile.
这是Dockerfile:
FROM ubuntu:14.04
MAINTAINER example <examplen@example.com>
# Update
RUN apt-get update
# Install Ruby and Rails dependencies
RUN apt-get install -y \
ruby \
ruby-dev \
build-essential \
libxml2-dev \
libxslt1-dev \
zlib1g-dev \
libsqlite3-dev \
nodejs \
curl
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
RUN curl -sSL https://get.rvm.io | bash -s stable --rails
RUN /bin/bash -c "source /usr/local/rvm/scripts/rvm"
# Install Rails
RUN gem install rails
# Create a new Rails app under /src/my-app
RUN mkdir -p …Run Code Online (Sandbox Code Playgroud)