Reputation: 4572
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:
# 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
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.
Upvotes: 4
Views: 1935
Reputation: 311645
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>
Upvotes: 1