How to sync files from a Docker container back to its host?


Zolt

Maybe I'm complicating this.

My goal is to create a Docker based workflow for Node.js application development on Windows.

  1. During development I will be able to run my app locally inside the container and still easily see the latest version (I don't want to rebuild the image every time to see the latest version).

  2. On the other hand, when I deploy to production, I want to "bake" the source files with all the dependencies into the container image ( npm install)

So I created two Vagrantfiles - one for the container and one for its host. Here's an excerpt from the latter:

Vagrant.configure(2) do |config|
  config.vm.provider "docker" do |docker|
    docker.vagrant_vagrantfile = "host/Vagrantfile"  # it references the host Vagrantfile
    docker.build_dir = "."  # we have a Dockerfile in the same dir
    docker.create_args = ['--volume="/usr/src/host:/usr/src/appcontainer:rw"']
  end
end

/usr/src/hostis a directory (without node_modules) containing all my source code. During the build Dockerfile, Docker will copy package.jsonto /usr/src/appcontainerand issue npm install, which is fine for my second requirement (deploy to production)

But my first requirement is to change the source code during development, so I mount it /usr/src/appcontaineras a volume pointing to the host directory /usr/src/host. However, this doesn't work because /usr/src/hostthere is no node_modulesfolder - the folder only exists in the container.

The whole problem seems simple - changing a file under Windows, it's visible in the Linux host VM as well as in its container, and vice versa... but I'm kind of stuck.

What is the best practice to achieve this synchronous behavior?

Feng

However, this doesn't work because /usr/src/host doesn't have a node_modules folder

You can use one of the methods described in this question , such as using a dedicated data volume . Or mount the host as a separate folder in the container.node_modules
node_modules

Related


How to sync files from a Docker container back to its host?

Zolt Maybe I'm complicating this. My goal is to create a Docker based workflow for Node.js application development on Windows. During development I will be able to run my app locally inside the container and still easily see the latest version (I don't want to

How to sync files from a Docker container back to its host?

Zolt Maybe I'm complicating this. My goal is to create a Docker based workflow for Node.js application development on Windows. During development I will be able to run my app locally inside the container and still easily see the latest version (I don't want to

How to sync files from a Docker container back to its host?

Zolt Maybe I'm complicating this. My goal is to create a Docker based workflow for Node.js application development on Windows. During development I will be able to run my app locally inside the container and still easily see the latest version (I don't want to

How to sync files from a Docker container back to its host?

Zolt Maybe I'm complicating this. My goal is to create a Docker based workflow for Node.js application development on Windows. During development I will be able to run my app locally inside the container and still easily see the latest version (I don't want to

How to sync files from a Docker container back to its host?

Zolt Maybe I'm complicating this. My goal is to create a Docker based workflow for Node.js application development on Windows. During development I will be able to run my app locally inside the container and still easily see the latest version (I don't want to

How to sync files from a Docker container back to its host?

Zolt Maybe I'm complicating this. My goal is to create a Docker based workflow for Node.js application development on Windows. During development I will be able to run my app locally inside the container and still easily see the latest version (I don't want to

How to sync from host to docker container using docker cp

Brenda Olivia Martis I am trying to do the following: Start a container in the background docker run -dit -p 8090:80 --name container repository:dockerfile bash I want to exclude subdirectories /datafrom/test docker cp /Users/$USER/test container:/test I thoug

How to sync from host to docker container using docker cp

Brenda Olivia Martis I am trying to do the following: Start a container in the background docker run -dit -p 8090:80 --name container repository:dockerfile bash I want to exclude subdirectories /datafrom/test docker cp /Users/$USER/test container:/test I thoug

How to sync from host to docker container using docker cp

Brenda Olivia Martis I am trying to do the following: Start a container in the background docker run -dit -p 8090:80 --name container repository:dockerfile bash I want to exclude subdirectories /datafrom/test docker cp /Users/$USER/test container:/test I thoug

How to sync from host to docker container using docker cp

Brenda Olivia Martis I am trying to do the following: Start a container in the background docker run -dit -p 8090:80 --name container repository:dockerfile bash I want to exclude subdirectories /datafrom/test docker cp /Users/$USER/test container:/test I thoug

How to sync from host to docker container using docker cp

Brenda Olivia Martis I am trying to do the following: Start a container in the background docker run -dit -p 8090:80 --name container repository:dockerfile bash I want to exclude subdirectories /datafrom/test docker cp /Users/$USER/test container:/test I thoug

How to copy files from host to Docker container?

username I'm trying to build a backup and restore solution for the Docker containers we use. I've created a Docker base image ubuntu:baseand don't want to rebuild it every time with a Dockerfile to add files to it. I want to create a script that runs from the

How to share files from Docker container to host

Ana Carolina I have a Docker container running fine. It generates some files in a directory /Project/userfiles.txt. I need these files for some testing purposes. However, when that container is stopped, everything will be deleted. So I need to copy this file f

How to share files from Docker container to host

Ana Carolina I have a Docker container running fine. It generates some files in a directory /Project/userfiles.txt. I need these files for some testing purposes. However, when that container is stopped, everything will be deleted. So I need to copy this file f

How to copy files from host to Docker container?

username I'm trying to build a backup and restore solution for the Docker containers we use. I've created a Docker base image ubuntu:baseand don't want to rebuild it every time with a Dockerfile to add files to it. I want to create a script that runs from the

How to edit Docker container files from host?

ascorbic acid Now that I've found a way to expose the hosts file to the container (-v option), I want to do the opposite: How to edit files from a running container using the host editor? sshfs might do the job, but since the running container is already some

How to copy files from host to Docker container?

username I'm trying to build a backup and restore solution for the Docker containers we use. I've created a Docker base image ubuntu:baseand don't want to rebuild it every time using the Dockerfile to add files to it. I want to create a script that runs from t

How to share files from Docker container to host

Ana Carolina I have a Docker container running fine. It generates some files in a directory /Project/userfiles.txt. I need these files for some testing purposes. However, when that container is stopped, everything will be deleted. So I need to copy this file f

Sync files between Docker container and host

JPG format The scenario is; I have a folder staticthat contains a file called sample_old.txtand mounts staticinto a container using docker-compose.yml. Then use to start the docker service docker-compose up. Then a function is called to create a new file sampl

Sync files between Docker container and host

JPG format The scenario is; I have a folder staticthat contains a file called sample_old.txtand mounts staticinto a container using docker-compose.yml. Then use to start the docker service docker-compose up. Then a function is called to create a new file sampl

Sync files between Docker container and host

JPG format The scenario is; I have a folder staticthat contains a file called sample_old.txtand mounts staticinto a container using docker-compose.yml. Then use to start the docker service docker-compose up. Then a function is called to create a new file sampl

Docker: Copy files from Docker container to host

username I'm thinking of using Docker to build my dependencies on a continuous integration (CI) server so that I don't have to install all the runtimes and libraries on the agent itself. To do this, I need to copy the build artifacts built inside the container

Docker: Copy files from Docker container to host

username I'm thinking of using Docker to build my dependencies on a continuous integration (CI) server so that I don't have to install all the runtimes and libraries on the agent itself. To do this, I need to copy the build artifacts built inside the container

Docker: Copy files from Docker container to host

username I'm thinking of using Docker to build my dependencies on a continuous integration (CI) server so that I don't have to install all the runtimes and libraries on the agent itself. To do this, I need to copy the build artifacts built inside the container

How to copy multiple files from container to host using Docker CP

Lucky Yagi I want to use wildcards to select multiple files from a directory in a container and use docker cp to copy these files from the container to the docker host. I can't find if docker cp provides support for using wildcards. docker cp fd87af99b650:/foo

How to copy multiple files from container to host using Docker CP

Lucky Yagi I want to use wildcards to select multiple files from a directory in a container and use docker cp to copy these files from the container to the docker host. I can't find if docker cp provides support for using wildcards. docker cp fd87af99b650:/foo

How to copy multiple files from container to host using Docker CP

Lucky Yagi I want to use wildcards to select multiple files from a directory in a container and use docker cp to copy these files from the container to the docker host. I can't find if docker cp provides support for using wildcards. docker cp fd87af99b650:/foo