0

I am running a simple Hello World world container with docker-compose.

There should be a mounted folder (with my files) at /root/sharedFolder but this folder is empty.

I am running Docker on Ubuntu OS (on top of my Windows server). And this works on a normal Ubuntu machine.

Any ideas?

docker-compose.yaml

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

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"]                                                                                                            
Antirreni91
  • 375
  • 3
  • 16
  • Possible duplicate of [Mount docker host volume but overwrite with container's contents](https://stackoverflow.com/questions/36107442/mount-docker-host-volume-but-overwrite-with-containers-contents) – David Maze Jul 09 '18 at 21:54

1 Answers1

0

Instead of doing echo in RUN, do it in CMD or ENRTYPOINT. RUN happens during the image build phase where as CMD happens when your container is up and running with the volumes.

  • RUN is done during image build step
  • CMD specifies the command executed by default when you run a built image.

You can also achieve the same with ENTRYPOINT

Google docker RUN vs CMD for more details.

Sachin Murali G
  • 575
  • 6
  • 25