Answers: <p>One could use <a href="https://docs.docker.com/engine/admin/volumes/volumes/#use-a-read-only-volume" rel="nofollow noreferrer">read-only volumes</a>. </p>
  
  <blockquote>
  <pre><code>docker run -d \
    -it \
    --name=nginxtest \
    -v nginx-vol:/usr/share/nginx/html:ro \
    nginx:latest
  </code></pre>
  </blockquote>
  
  <p>If one would like to use the same volume in multiple containers then one could specify the following when running each container:</p>
  
  <pre><code>-v vol:/usr/share/nginx/html:ro
  </code></pre>
  
  <p>Note: one could use <code>ro</code> to ensure that the volume is read-only to prevent that multiple containers will write at the same time to the same volume and prevent issues.</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-10-06T10:27:42.663Z
Answers: Yes, but in this case, I have a doubt that VM will be started because I do there: vagrant up; vagrant suspend.
Answers: user54
Answers: CC BY-SA 3.0
Answers: 2017-10-06T10:29:02.013Z
Answers: Why would you like to run the containers in a VM and not on the host machine itself?
Answers: 030
Answers: CC BY-SA 3.0
Answers: 2017-10-06T10:31:12.593Z
Answers: Containers will be run on host and inside container will be run VM.
Answers: user54
Answers: CC BY-SA 3.0
Answers: 2017-10-06T10:37:46.173Z
Answers: why do you run a VM in a container?
Answers: 030
Answers: CC BY-SA 3.0
Answers: 2017-10-06T11:30:40.277Z
Answers: Because that VM will be FreeBSD VM. I can not run FreeBSD container under Linux and I can not setup FreeBSD as host OS to use FreeBSD containers as long as Docker is an experimental thing in FreeBSD and Kubernetes is not supported under FreeBSD.
Answers: user54
Answers: CC BY-SA 3.0
Answers: 2017-10-06T11:33:38.183Z
Answers: That is valuable information that should be added to the question in my opinion
Answers: 030
Answers: CC BY-SA 3.0
Answers: 2017-10-06T11:38:22.187Z
Answers: The question was updated.
Answers: user54
Answers: CC BY-SA 3.0
Answers: 2017-10-06T10:26:04.907Z
Answers: 2017-10-06T10:28:27.333Z
Answers: 2017-10-06T10:28:27.333Z
Answers: 030
Body: <p>I have Docker image which contains config files of VirtualBox and I want to use this image for running multiple containers in parallel.</p>
  
  <p>Config files of VM are being stored on host OS, however, I am afraid of issues with config data of VMs which may occur because of parallel accessing by multiple containers. 
  All containers will be started by Jenkins automatically.</p>
  
  <p>Therefore, could you please tell what is the best way to share data between containers to avoid data corruption because of parallel usage?</p>
  
  <p>Please note: I can not run FreeBSD container under Linux and I can not setup FreeBSD as host OS to use FreeBSD containers as long as Docker is an experimental thing in FreeBSD and Kubernetes is not supported under FreeBSD.</p>
  
Comments: CC BY-SA 3.0
Comments: 2017-10-06T11:35:03.653Z
Comments: Please update the question.
Comments: 030
Comments: CC BY-SA 3.0
Comments: 2017-10-06T12:00:56.997Z
Comments: Why not running the VM from host ? VirtualBox allow to share a disk between VMs solving your problem, your main problem is adding a process segregation between your virtualbox processes , in brief, you're trying to work against docker isolation for no reason, remove docker from the equation ...
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2017-10-06T12:02:18.493Z
Comments: Side note: I'm downvoting the question because there's no explanation of why you're using docker in this case.
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2017-10-06T12:04:06.750Z
Comments: Because there is Kubernetes cluster which will manage and redistribute containers in parallel. All tests/instructions will be started from Jenkins.
Comments: user54
Comments: CC BY-SA 3.0
Comments: 2017-10-06T12:29:27.783Z
Comments: Virtualbox, k8s? huh? I agree with @Tensibai
Comments: 030
Comments: CC BY-SA 3.0
Comments: 2017-10-06T13:02:38.087Z
Comments: Are your config files being modified by the containers? What kind of issues are their with accessing the config files in parallel?
Comments: Preston Martin
Comments: CC BY-SA 3.0
Comments: 2017-10-06T14:43:27.090Z
Comments: @user54 Well back to root question: Why on earth running those test on top of a kubernetes cluster at all ? Sometimes you have to take a step back and see something is just a footgun and not a proper solution. Use a normal host with a jenkins agent and start multiples virtualbox on it. what is the target goal ? just testing under freebsd ? creating a vbox image of freebsd for redistribution ? Why freebsd and not switching OS if it brings you that much problems ?
Comments: Tensibai
Tags: <docker>
Title: The best way to share volume with config data between multiple Docker containers
UserDisplayName: user54
ThreadText: # The best way to share volume with config data between multiple Docker containers
  
  (Asked by: username_0 on 2017-10-05)
  
  I have Docker image which contains config files of VirtualBox and I want to use this image for running multiple containers in parallel.
  
  Config files of VM are being stored on host OS, however, I am afraid of issues with config data of VMs which may occur because of parallel accessing by multiple containers.
  All containers will be started by Jenkins automatically.
  
  Therefore, could you please tell what is the best way to share data between containers to avoid data corruption because of parallel usage?
  
  Please note: I can not run FreeBSD container under Linux and I can not setup FreeBSD as host OS to use FreeBSD containers as long as Docker is an experimental thing in FreeBSD and Kubernetes is not supported under FreeBSD.
  
  **Tags:** docker
  
  > **Comments:**
  > **username_1**: Please update the question.  
  > **username_2**: Why not running the VM from host ? VirtualBox allow to share a disk between VMs solving your problem, your main problem is adding a process segregation between your virtualbox processes , in brief, you're trying to work against docker isolation for no reason, remove docker from the equation ...  
  > **username_2**: Side note: I'm downvoting the question because there's no explanation of why you're using docker in this case.  
  > **username_0**: Because there is Kubernetes cluster which will manage and redistribute containers in parallel. All tests/instructions will be started from Jenkins.  
  > **username_1**: Virtualbox, k8s? huh? I agree with @username_2  
  > **username_3**: Are your config files being modified by the containers? What kind of issues are their with accessing the config files in parallel?  
  > **username_2**: @username_0 Well back to root question: Why on earth running those test on top of a kubernetes cluster at all ? Sometimes you have to take a step back and see something is just a footgun and not a proper solution. Use a normal host with a jenkins agent and start multiples virtualbox on it. what is the target goal ? just testing under freebsd ? creating a vbox image of freebsd for redistribution ? Why freebsd and not switching OS if it brings you that much problems ?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-10-06. Score: 1 | Accepted answer
  
  One could use [read-only volumes](https://docs.docker.com/engine/admin/volumes/volumes/#use-a-read-only-volume).
  
  > ```
  > docker run -d \
  >   -it \
  >   --name=nginxtest \
  >   -v nginx-vol:/usr/share/nginx/html:ro \
  >   nginx:latest
  >
  > ```
  
  If one would like to use the same volume in multiple containers then one could specify the following when running each container:
  
  ```
  -v vol:/usr/share/nginx/html:ro
  
  ```
  
  Note: one could use `ro` to ensure that the volume is read-only to prevent that multiple containers will write at the same time to the same volume and prevent issues.
  
  > **Comments:**
  > **username_0**: Yes, but in this case, I have a doubt that VM will be started because I do there: vagrant up; vagrant suspend.  
  > **username_1**: Why would you like to run the containers in a VM and not on the host machine itself?  
  > **username_0**: Containers will be run on host and inside container will be run VM.  
  > **username_1**: why do you run a VM in a container?  
  > **username_0**: Because that VM will be FreeBSD VM. I can not run FreeBSD container under Linux and I can not setup FreeBSD as host OS to use FreeBSD containers as long as Docker is an experimental thing in FreeBSD and Kubernetes is not supported under FreeBSD.  
  > **username_1**: That is valuable information that should be added to the question in my opinion  
  > **username_0**: The question was updated.  
  
  ---
  
  