我最近尝试为开发django项目创建一个docker环境。
我注意到只有在使用' docker run'才能访问通过Dockerfile创建或复制的文件。或者' docker attach',在这种情况下,对于后者,您可以进入并查看您在适当位置移动的任何文件。
但是,当运行“docker exec”时,容器似乎无法显示这些文件的任何痕迹。为什么会这样?
Dockerfile
############################################################
# Dockerfile to run a Django-based web application
# Based on an Ubuntu Image
############################################################
# Set the base image to use to Ubuntu
FROM ubuntu:14.04
# Set env variables used in this Dockerfile (add a unique prefix, such as DOCKYARD)
# Local directory with project source
ENV DOCKYARD_SRC=hello_django
# Directory in container for all project files
ENV DOCKYARD_SRVHOME=/srv
# Directory in container for project source files
ENV DOCKYARD_SRVPROJ=/srv/hello_django
# Update the default application repository sources list
RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y python python-pip
# Create application subdirectories
WORKDIR $DOCKYARD_SRVHOME
RUN sudo mkdir media static logs
# Copy application source code to SRCDIR
COPY $DOCKYARD_SRC $DOCKYARD_SRVPROJ
# Install Python dependencies
RUN pip install -r $DOCKYARD_SRVPROJ/requirements.txt
# Port to expose
EXPOSE 8000
# Copy entrypoint script into the image
WORKDIR $DOCKYARD_SRVPROJ
COPY ./docker-entrypoint.sh /
使用上面的Dockerfile,我的源文件夹hello_django被复制到/ srv / hello_django中的适当位置,我的docker-entrypoint.sh也被成功移动到root。
我可以在' docker run -it bash' /#39; docker attach'中确认这一点,但无法通过' docker exec -it访问其中任何一个bash",例如。
(从this tutorial获得的Dockerfile)。
问题演示
Image proof of problem http://image.prntscr.com/image/2b72ddaeebc44a1cb517f2d8f20d4668.png
我通过流浪汉运行码头工人,如果这是相关的。
Vagrantfile
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 8000, host: 8000
config.vm.provision "docker" do |d|
d.pull_images "django"
end