更改我的项目文件不会更改Docker机器中的文件 [英] Changing my project files doesn't change files inside the Docker machine

查看:282
本文介绍了更改我的项目文件不会更改Docker机器中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Docker来改善我的工作流程。我在Windows 10主页上安装了Docker Toolbox for Windows(自从Docker据说只能在专业上工作)。我正在使用 mgexhev的角色种子,声称提供完整的码头支持。有一个docker-compose.yml文件链接./.docker/angular-seed.development.dockerfile。



在git克隆种子项目之后,我可以通过运行种子项目的github页面。所以我可以在运行后看到应用程序:

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

但是当我使用Visual Studio代码更改代码并保存livereload不起作用。我可以看到我的更改的唯一方法是重新运行build和up命令(重新运行npm install; 5min)。



Docker的文档他们说将主机目录作为数据卷安装,以便能够更改源代码并实时查看其对应用程序的影响

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

但是当我使用docker-compose时,我不知道这是对的吗?我也尝试运行:

  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 / -seed
docker run -p 5555:5555 -v $(pwd):/ home / app / -w/ home / app /angular-seed
pre>

和许多类似的命令,但似乎没有任何工作。



我尝试将我的项目从C:/ dev / project移动到home,因为我读到某个地方可能会有一些访问权限问题不使用home目录,但是这没有什么区别。



我也有点困惑,说明说访问localhost:5555。我必须去dockerIP:5555看到应用程序(以防这有助于任何人明白为什么我的代码不会在Docker容器内更新)。



当然我的更改应该自动移动到docker环境或docker对开发不是很有用:)

解决方案

查看已链接到的docker-compose.yml,我看不到任何卷条目。没有这种情况,您的主机上的文件和容器内的文件之间无法连接。您将需要一个包含卷条目的docker-compose.yml,如:

 版本:'2'

服务:

角形种子:
构建:
上下文:。
dockerfile:./.docker/angular-seed.development.dockerfile
命令:npm start
container_name:angular-seed-start
image:angular-seed
网络:
- dev-network
ports:
- '5555:5555'
卷:
- 。:/ home / app / angular-seed

网络:
dev-network:
驱动程序:桥

Docker机器在虚拟机箱VM内部运行停放码头。默认情况下,我相信c:\Users被共享到VM中,但是您需要检查虚拟框设置以确认这一点。您尝试映射到容器的任何主机目录映射到VM,因此如果您的文件夹未共享到该虚拟机中,则不会包含您的文件。



使用IP,localhost适用于Linux主机和较新版本的docker for windows / mac。旧的基于docker-machine的安装需要使用虚拟盒VM的IP。


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 :)

解决方案

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.

这篇关于更改我的项目文件不会更改Docker机器中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆