How to sync code between container and host using docker layout?

So far, I have used the local LAMP stack to develop my web projects and deploy them manually on the server. For the next project, I want to use docker and docker-compose to create mariaDB, NGINX and the project container for easy development and deployment.

In development, I want my code directory on the host machine to be synchronized with the docker container. I know this can be achieved at startup

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

in cli, as indicated here , but I want to do this in the file of the vock-compose file.

As long as the docker-composer.yml file looks like this:

version: '2'

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

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

.

+4
1

, host:container services.myProj.volumes :

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

, volumes.

:

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

docker-compose volumes, docker volume create . , . , , - :

docker volume create myCodeVolume
docker create --links db -v myCodeVoume:/var/www myProj
+3

Source: https://habr.com/ru/post/1672637/


All Articles