#How do I set-up a new astro project inside a docker container?

36 messages · Page 1 of 1 (latest)

late aurora
#

Hi. I am creating the astro project with the default wizard inside docker container and I get the message that the dir is not empty. I can't move past this step. Does the wizard provide a way to force to continue with the setup even when the dir is not empty or maybe it shows a YES or NO? For me it just shows the message in red and there are no any options displayed so I'm wandering if it's just not showing it right to me because of the docker/windows terminal/alpine trimmed distro combo or if there are no options indeed.

For context.
I am running everything (the Node, the astro) inside the container, I only have the project files dir mounted to the host so that I can edit on the host.
The dir I am creating the project in, is in fact empty when I run the wizard, the only thing that is in it - is the empty node_modules dir, that is a result of mounting that dir to an internal docker volume (that is one of the requirements for the auto reload to work with docker).

When I create the project in a temp subdir and then copy it up one level where the node_modules is also located and then run npm install - after this when I run the dev mode it errors because it can't find astro. So this workaround is not working.

So at the moment it looks like there is no Docker friendly way of setting up the project.

granite fulcrum
#

Have you checked this out?

granite fulcrum
late aurora
#

that is about deployment containers, when everything is built and is ready to ship. I am asking about setting up a dev env locally, so different things

granite fulcrum
#

Why are you wanting to set up a new project inside a container? Normally you containerize a project.

late aurora
#

This is for development. I want all of my dev ecosystem inside containers so that I don't depend on the host. If my host OS breaks, or if I change the host OS or if I move to another machine for developing - I just want to install docker and pick-up where I left.

granite fulcrum
#

Well if you have a docker container. You can execute commands inside of it. Have you tried that?

late aurora
#

yes, that's what I do. That's what this post is about

granite fulcrum
#

Okay. So what directory are you trying to make your project in?

late aurora
#

I start the container with interactivity support, then connect to it and run the wizard and npm install. but I can't get past the not empty dir warning point

granite fulcrum
#

Okay. Connect to your container. Then run a pwd and then ls and show me what it says.

#

How are you mounting your volume to your hose?

#

Host*

rich path
granite fulcrum
#

Yeah I think a vscode dev container is what you are looking for.

late aurora
#

I have a node_modules dir mounted to an anonymous docker volume (that's not on the host but inside the docker filesystem). This node_modules dir seems to be THE problem, that's why the astro says that dir is not empty.

#

so now I have to add a third container version (to be used before the INIT version), without the node_modules dir mounted because astro will not allow me to init the project otherwise

#

this makes the workflow a bit busy. Having an option to force install to a non-empty dir or to ignore the node_modules dir in this check would help

neat flax
#

There's a different fix to that, you need to set a vite flag. Let me grab the code really quick

#
// https://astro.build/config
export default defineConfig({
  // ...
  vite: {
    server: {
      host: "0.0.0.0",
      watch: {
        usePolling: true
      },
      port: 3000,
      hmr: {
        clientPort: 3000
      }
    }
  },
  // ...
});
#

The important part here is the usePolling: true

#

Everything else you can change to your needs, the port doesn't need to be 3000

late aurora
neat flax
#

I'd still do that anyway

#

Wait actually let me check how I did it

#

I added it, not sure if they're required but I'd leave them in

late aurora
#

because I can't have it that way. when I mount it like that the astro wizard will not allow me to init the project

neat flax
#

Feel free to try it without, I'm not sure what side effects that might have

late aurora
#

OK, I'll test it. thanx

neat flax
#

Should this not have worked I'm happy to share my setup for how I got HMR working

late aurora
#

it works, thanks!