Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch not triggering build when file changed inside Docker #4109

Closed
benedictdudel opened this issue Feb 17, 2018 · 11 comments
Closed

Watch not triggering build when file changed inside Docker #4109

benedictdudel opened this issue Feb 17, 2018 · 11 comments

Comments

@benedictdudel
Copy link

Description

I created a minimal Dockerfile for developing a Gatsby page. Unfortunately changes in files do not trigger a rebuild inside a Docker container. See below for the minimal Dockerfile.

While debugging the problem I have noticed that the container and host both got a different timezone. So files in the container have a different timestamp:

Container:
-rw-r--r-- 1 node staff 245 Feb 17 14:17 page-2.js

Host:
-rw-r--r-- 1 user 370035326 245 17 Feb 15:17 page-2.js

Maybe the different timezones causing the problem but I never encountered any problem with other "watchers".

Environment

Gatsby version: latest
Node.js version: LTS
Operating System: macOS (host) / Debian (container)

Actual result

A changed file doesn't trigger the rebuild.

Expected behavior

A changed file should trigger the rebuild.

Steps to reproduce

1. Create a Dockerfile with the following content

FROM node:carbon

WORKDIR /var/www

COPY package.json ./

RUN yarn global add gatsby-cli
RUN yarn install

COPY gatsby-*.js ./

EXPOSE 8000

ENV NODE_ENV=development

CMD ["gatsby", "develop", "--host", "0.0.0.0", "--port", "8000"]

2. Build the container

$ docker build -t gatsby .

3. Create a container

$ docker run -v $(pwd)/src:/var/www/src --interactive --tty --detach --name test --publish 8000:8000 gatsby

4. Change any file in src directory and verify file changed in the container

$ docker exec -it test bash
$ ls -l src
@m-allanson
Copy link
Contributor

@aripalo recently added a Gatsby Dockerfile at https://github.com/aripalo/gatsby-docker/. What happens if you try your site with that Docker image, do you see the same issue?

@benedictdudel
Copy link
Author

Thanks for you tip. But unfortunately I had encountered the same behaviour with the Dockerfile of @aripalo. The file in the container changed but doesn't trigger the build.

@m-allanson
Copy link
Contributor

m-allanson commented Feb 20, 2018

Hmm I can't replicate the issue you've described, using your container or the gatsby-docker container.

Changing files in the src folder will trigger a rebuild. Doing either of:

  • running the container without the --detached flag
  • using docker logs -f

will show gatsby develop's output, showing the 'Compiling' message after a file change. Here's a screenshot of my terminal output, running without --detached:

screen shot 2018-02-20 at 10 32 33

You can see the two file changes at the bottom, each one trggering a new pair of 'Compiling... Compiled' messages.

I'm running macOS and Docker Version 17.12.0-ce-mac49 (21995). Is there something else in your setup that could be causing this?

@benedictdudel
Copy link
Author

Yesterday I tried the following things:

  • removed docker & docker-machine
  • installed current version via homebrew cask
  • deleted the default machine of docker-machine

But unfortunately no luck. I don't know where a difference between yours and my setup could be..

@m-allanson
Copy link
Contributor

Hmm I'm not sure what else to suggest. Here's the output from my docker version, maybe that helps?

docker version
Client:
 Version:	17.12.0-ce
 API version:	1.35
 Go version:	go1.9.2
 Git commit:	c97c6d6
 Built:	Wed Dec 27 20:03:51 2017
 OS/Arch:	darwin/amd64

Server:
 Engine:
  Version:	17.12.0-ce
  API version:	1.35 (minimum version 1.12)
  Go version:	go1.9.2
  Git commit:	c97c6d6
  Built:	Wed Dec 27 20:12:29 2017
  OS/Arch:	linux/amd64
  Experimental:	true

@m-allanson
Copy link
Contributor

m-allanson commented Feb 27, 2018

I think I installed docker "the old fashioned way", by downloading Docker for Mac from https://docs.docker.com/docker-for-mac/install/

@benedictdudel
Copy link
Author

Soo... I've came across with some other troubles when using Docker for other applications and it seems like that the problem did had something to do with docker-machine. I have now installed the edge version of Docker for Mac and skipped using docker-machine for my containers. Et voilá my Dockerfile from above is working fine now. Changes are now triggerd :)

Thank you very much for your effort and keep up the good work :)

@m-allanson
Copy link
Contributor

Great! I'm glad it worked out :)

@onichandame
Copy link

@benedictdudel I am seeing the exactly same issue on Windows. Would you mind sharing the detailed steps? I have the latest nightly built Docker desktop with wsl 2 enabled.

@jscontreras
Copy link

When webpack dev server tries to look for changes and you are using wsl or docker the fsevents are not going to be fired (taht's why it doesn't trigger the refresh) so you need to override the watch webpack dev server options a little bit.
(in your gabsy-node.js)

/**
 * Implement Gatsby's Node APIs in this file.
 *
 * See: https://www.gatsbyjs.org/docs/node-apis/
 */

// You can delete this file if you're not using it
const path = require('path');

exports.onCreateWebpackConfig = ({ actions, getConfig }) => {
  const config = getConfig();
  config.devServer = {
    watchOptions: {
      aggregateTimeout: 500, // delay before reloading
      poll: 1000 // enable polling since fsevents are not supported in docker
    }
  };
  actions.replaceWebpackConfig(config);
};

@florent-andre
Copy link

As of gatsby 4.22 in docker on linux, I get this working with:

export function onCreateWebpackConfig({ actions }){
  const watchConf = {
    watchOptions: {
      aggregateTimeout: 500, // delay before reloading
      poll: 1000, // enable polling since fsevents are not supported in docker
      ignored: ['**/node_modules', '**/public'] // keep CPU usage minimal
    }
  }
  actions.setWebpackConfig(watchConf)
}
  • setWebpackConfig seems prefered to replaceWebpackConfig by docs

Thanks to you all for this long path of help !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants