Changing my project files doesn't change files

2019-07-28 17:41发布

I'm trying to use Docker to improve my workflow. I installed "Docker Toolbox for Windows" on my Windows 10 home edition (since Docker supposedly only work on professional). I'm using mgexhev's angular-seed which claim to provide full docker support. There is a docker-compose.yml file which links a ./.docker/angular-seed.development.dockerfile.

After git cloning the seed project I can start it by running the commands given on the seed project's github page. So I can see the app after running:

$ docker-compose build
$ docker-compose up -d

But when I change code with Visual Studio Code and save the livereload doesn't work. The only way I can see my changes is by re-running the build and up commands (which re-runs npm install; 5min).

In Docker's documentation they say to "Mount a host directory as a data volume" in order to be able to "change the source code and see its effect on the application in real time"

docker run -v //c/<path>:/<container path>

But I'm not sure this is right when I'm using docker-compose? I have also tried running:

docker run -d -P --name web -v //c/Users/k/dev/:/home/app/ angular-seed
docker run -p 5555:5555 -v //c/Users/k/dev/:/home/app/ -w "/home/app/" angular-seed
docker run -p 5555:5555 -v $(pwd):/home/app/ -w "/home/app/" angular-seed

and lots of similar commands but nothing seems to work.

I tried moving my project from C:/dev/project to home because I read somewhere that there might be some access right issues not using the "home" directory, but this made no difference.

I'm also a bit confused that the instructions say visit localhost:5555. I have to go to dockerIP:5555 to see the app (in case this help anyone understand why my code doesn't update inside of my docker container).

Surely my changes should move in to the docker environment automatically or docker is not very useful for development :)

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-07-28 18:45

Looking at the docker-compose.yml you've linked to, I don't see any volume entry. Without that, there's no connection possible between the files on your host and the files inside the container. You'll need a docker-compose.yml that includes a volume entry, like:

version: '2'

services:

  angular-seed:
    build:
      context: .
      dockerfile: ./.docker/angular-seed.development.dockerfile
    command: npm start
    container_name: angular-seed-start
    image: angular-seed
    networks:
      - dev-network
    ports:
      - '5555:5555'
    volumes:
      - .:/home/app/angular-seed

networks:
  dev-network:
    driver: bridge

Docker-machine runs docker inside of a virtual box VM. By default, I believe c:\Users is shared into the VM, but you'll need to check the virtual box settings to confirm this. Any host directories you try to map into the container are mapped from the VM, so if your folder is not shared into that VM, your files won't be included.

With the IP, localhost works on Linux hosts and newer versions of docker for windows/mac. Older docker-machine based installs need to use the IP of the virtual box VM.

查看更多
登录 后发表回答