简体   繁体   中英

Docker - Volume not mounting latest files in container

The Problem

When I start a new container in Docker, I want to mount a volume so that I get the latest updates to any files on my host machine and can work with them in my container. However, what I am finding is that Docker is mounting my volumes when I build the image . What I want instead is to mount the volumes when I create a new container.

Because I am using Docker to manage my development environment, this means that whenever I update a little piece of code, I have to rebuild my development environment Docker image , which takes usually around 20-30 mins. Obviously, this is not the functionality I want from Docker.

Here is what I am using to build my development environment container:


Dockerfile

# This docker file constructs an Ubuntu development environment and configures the compiler/libs needed
FROM ubuntu:latest

ADD . /gdms-rcon/liaison
WORKDIR /gdms-rcon/liaison

RUN rm -rf ./build
RUN apt-get update
RUN apt-get install -y -f gcc g++ qtbase5-dev cmake mysql-client

fig.yml

liaison:
  build: ./liaison/
  command: /bin/bash
  volumes:
    - liaison:/gdms-rcon/liaison
  working_dir: /gdms-rcon/liaison

I also use a fig.yml file to make it easier to build.

To run, I use: fig build

To access my container to compile my source code, I use: docker run -it <container_id>

Maybe I'm doing something wrong with my commands? I don't use fig up because it won't give me an interactive shell, so I use docker run -it <container_id> instead. I chose to use fig so that it would mount my volumes automatically, but it isn't working as I would have hoped.


Here is an image to more clearly demonstrate my problem

在此处输入图片说明

If you're not using fig to start the container, the volumes line in your fig.yml isn't doing anything useful. If you need an interactive shell, fig is not really the tool for you.

Just docker build your image like normal, and then use the -v flag to docker run to mount the volume:

docker run -it -v <hostpath>:<containerpath> <imageid>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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