简体   繁体   English

Docker撰写yml“ volume”在Ubuntu OS上不起作用

[英]Docker compose yml “volume” not working on Ubuntu OS

I am running a simple Hello World world container with docker-compose. 我正在使用docker-compose运行一个简单的Hello World世界容器。

There should be a mounted folder (with my files) at /root/sharedFolder but this folder is empty. /root/sharedFolder应该有一个已安装的文件夹(包含我的文件),但是该文件夹为空。

I am running Docker on Ubuntu OS (on top of my Windows server). 我在Ubuntu OS(在Windows服务器顶部)上运行Docker。 And this works on a normal Ubuntu machine. 这适用于普通的Ubuntu计算机。

Any ideas? 有任何想法吗?

docker-compose.yaml docker-compose.yaml

version: '3'                                                                                                                    
services:                                                                                                                       
  web:                                                                                                                          
    build: .                                                                                                                    
    volumes:                                                                                                                    
    - ".:/root/sharedFolder" 

Dockerfile: Dockerfile:

#FROM - Image to start building on.                                                                                             
FROM ubuntu:14.04                                                                                                               

#MAINTAINER - Identifies the maintainer of the dockerfile.                                                                      
MAINTAINER ian.miell@gmail.com                                                                                                  

#RUN - Runs a command in the container                                                                                          
RUN echo "Hello world" > /root/hello_world.txt                                                                                  


#CMD - Identifies the command that should be used by default when running the image as a container.                             
CMD ["sleep", "400"]                                                                                                            

Instead of doing echo in RUN, do it in CMD or ENRTYPOINT. 与其在RUN中执行回显,不如在CMD或ENRTYPOINT中执行它。 RUN happens during the image build phase where as CMD happens when your container is up and running with the volumes. RUN发生在映像构建阶段,CMD发生在容器启动并随卷运行时。

  • RUN is done during image build step 在映像构建步骤中完成运行
  • CMD specifies the command executed by default when you run a built image. CMD指定在运行构建的映像时默认执行的命令。

You can also achieve the same with ENTRYPOINT 您也可以使用ENTRYPOINT实现相同的目的

Google docker RUN vs CMD for more details. Google docker RUN vs CMD了解更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM