Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

533
Views
How to sync code between container and host using docker-compose?

Until now, I have used a local LAMP stack to develop my web projects and deploy them manually to the server. For the next project I want to use docker and docker-compose to create a mariaDB, NGINX and a project container for easy developing and deploying.

When developing I want my code directory on the host machine to be synchronised with the docker container. I know that could be achieved by running

docker run -dt --name containerName -v /path/on/host:/path/in/container

in the cli as stated here, but I want to do that within a docker-compose v2 file.

I am as far as having a docker-composer.yml file looking like this:

version: '2'

services:
    db:
        #[...]
    myProj:
        build: ./myProj
        image: myProj
        depends_on:
            - db
        volumes:
            myCodeVolume:/var/www
volumes:
    myCodeVolume:

How can I synchronise my /var/www directory in the container with my host machine (Ubuntu desktop, macos or Windows machine)?

Thank you for your help.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It is pretty much the same way, you do the host:container mapping directly under the services.myProj.volumes key in your compose file:

version: '2'
services:
    ...
    myProj:
        ...
        volumes:
            /path/to/file/on/host:/var/www

Note that the top-level volumes key is removed.

This file could be translated into:

docker create --links db -v /path/to/file/on/host:/var/www myProj

When docker-compose finds the top-level volumes section it tries to docker volume create the keys under it first before creating any other container. Those volumes could be then used to hold the data you want to be persistent across containers. So, if I take your file for an example, it would translate into something like this:

docker volume create myCodeVolume
docker create --links db -v myCodeVoume:/var/www myProj
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!