Hey, welcome back. This article is part of the Dockerize series, make sure to checkout the Introduction where I go over some concepts we are going ...
For further actions, you may consider blocking this person and/or reporting abuse
This is great! I like putting react apps in containers!
I created a docker compose files that runs
create-react-app
based apps loacally on Docker!dev.to/salhernandez/containerize-b...
that's amazing, thanks for sharing!
when i am running the dev image it's building it correctly but when i run the production one i got this error :
i checked the code and it's exactly the same as yours!
Add to docker-compose.dev.yml for live reload
environment:
- WATCHPACK_POLLING=true
updated:
version: "3.8"
services:
app:
container_name: app-dev
image: app-dev
build:
target: development
volumes:
- ./src:/app/src
ports:
- 3000:3000
environment:
- WATCHPACK_POLLING=true
thank you!
The Compose file is invalid because:
Service app has neither an image nor a build context specified. At least one must be provided.
I have similar code as the tutorial tho I am using ubuntu
The Compose file is invalid because:
Service app has neither an image nor a build context specified. At least one must be provided.
Hey, thank you for reporting this. I've updated the article to include context...are you on the latest docker-compose version?
Great article, but unfortunately not a word about using
process.env
variables neither here nor in "dockerizing node app" articleIn CRA all the file under /static folder can be cached without problem (they include hash in their filename). So se paragraph "Optimizing static assets" can be improved.
Just the file under the "public" folder cannot be cached by the browser.
However nginx has a optimal built-in cache strategy.
Hi, I'm only trying to reproduce the steps for production. I'm getting:
yarn run v1.22.17
error Command "build" not found.
Thanks! This just saved me on M1 (ran into an issue with Node dependencies not installing properly).
I’m glad it helped!
After you have updated the Dockerfile for production, you have another two stages - one which actually builds the react app, and the last stage which grabs those built static files from the build step and serves them via NGINX.
Firstly, is the lower case 'as' in the nginx build step a typo or does that do something different to 'AS'.
Secondly, in the docker-compose.prod.yml file, you set the build target as 'production' - ie the last nginx stage in the docker file. How can that run successfully if the build stage it relies on has not been run yet? Is that build stage called when the nginx stage runs?
Hey, nice catch! yes it's a typo and should be 'AS', in dockerfile lowercase syntax also works exactly the same but it's not prefered..i'll update it to upper case..thank you
For the second question, docker automatically understands that "builder" is used inside the prod stage so it runs the builder first..so the seq of events are like this:
Hi, thank you very much for this article.
There's a lot of articles about that, but not for the build.
Glad it was helpful!
This is neat but you could achieve equal or better results by just serving the static files from a CDN/storage service like S3
Yes definitely! That is usually my goto solution but many orgs usually run on k8s or equivalent nowadays
Hi, article easy to reproduce, thanks! But for real I don't understand why I need containers? Only for different versions of node and packages?
Thanks! yes, we don't have to use them but I find them to be useful for the following:
...and many more!
when i run the docker compose file im getting this error
The Compose file is invalid because:
Service app has neither an image nor a build context specified. At least one must be provided.