我正在尝试使用docker文件挂载文件夹,而不是在构建时复制它。我们使用git进行开发,并且我不希望每次更改测试时都重建映像。
我的docker文件现在就是这样
#set base image
FROM centos:centos7.2.1511
MAINTAINER Alex <alex@app.com>
#install yum dependencies
RUN yum -y update \\
&& yum -y install yum-plugin-ovl \
&& yum -y install epel-release \
&& yum -y install net-tools \
&& yum -y install gcc \
&& yum -y install python-devel \
&& yum -y install git \
&& yum -y install python-pip \
&& yum -y install openldap-devel \
&& yum -y install gcc gcc-c++ kernel-devel \
&& yum -y install libxslt-devel libffi-devel openssl-devel \
&& yum -y install libevent-devel \
&& yum -y install openldap-devel \
&& yum -y install net-snmp-devel \
&& yum -y install mysql-devel \
&& yum -y install python-dateutil \
&& yum -y install python-pip \
&& pip install --upgrade pip
# Create the DIR
#RUN mkdir -p /var/www/itapp
# Set the working directory
#WORKDIR /var/www/itapp
# Copy the app directory contents into the container
#ADD . /var/www/itapp
# Install any needed packages specified in requirements.txt
#RUN pip install -r requirements.txt
# Make port available to the world outside this container
EXPOSE 8000
# Define environment variable
ENV NAME itapp
# Run server when the container launches
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
我已经注释掉了itapp Django文件的创建和复制,因为我想安装它们,(我需要先重建它吗?)
然后我的安装命令是
docker run -it -v /Users/alex/itapp:/var/www/itapp itapp bash
我现在收到错误:
bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_MESSAGES: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_NUMERIC: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_TIME: cannot change locale (en_US.UTF-8): No such file or directory
并且dev实例不会运行。
我如何将工作目录设置为我在运行时挂载的卷?
答案 0 :(得分:1)
尝试此命令。 -w WORKDIR
中的docker run
选项设置容器内的工作目录。
docker run -d -v /Users/alex/itapp:/var/www/itapp -w /var/www/itapp itapp
此外,您还可以将容器端口映射到主机端口,以便能够访问,例如,从浏览器访问您的应用。
为此,请使用以下命令。
docker run -d -p 8000:8000 -v /Users/alex/itapp:/var/www/itapp -w /var/www/itapp itapp
在此之后,您的应用应该在localhost:8000