5173
. Go to http://localhost:5173 to see your app.
The dev server is enabled with HMR, so it hot reloads the
application when you make changes.
<root>/index.html
as the build entry point
and produces an application bundle that is suitable to be served over a static hosting service. You can read more about
building for production in the Vite guide.
The output is found in the <root>/dist
directory unless configured to a different path.
npm run preview
to start a production-like local web server.vite preview
is intended for previewing the build locally and not meant as a production
server.nginx.conf.template
in the root of your project. We won’t be using this template now; we’ll use it to
run the Nginx server inside the Docker container.
Note two important blocks in this configuration:
index.html
from the files we built using Ember, stored in the /usr/share/nginx/html
folder. We
will copy the assets to this folder while building the Docker application.
And then the API block:
example.com
. Whenever an API call is made to
example.com/api
, the nginx server acts as a reverse proxy server and forwards the request to the backend server.
You can use reverse proxying to navigate the traffic that is inbound to nginx. The reverse proxy server also acts as a
mask, hiding the real backend from the outside world.
.dockerignore
file and add the contents that should not be copied over
to the Docker file system.
react-app
image for the platform linux/amd64
and tags it as latest
.
If you are locally testing your application, you can skip the platform
key to build the images.
-it
: enables interactivity with TTY.--rm
: tells the Docker Daemon to clean up the container and remove the file system after the container exits.--name react-app
: Name of the container react-app
.-e PORT=3000
: Sets the environment variable PORT in Docker to 3000
.-e BACKEND_PORT=3001
: Sets the environment variable BACKEND_PORT in Docker to 3001
.-e BACKEND_HOST=host.docker.internal
: Sets the environment variable BACKEND_HOST in Docker to
host.docker.internal
.-d
: Runs the container in detached (background) mode. You can skip the flag to see the logs directly in your
terminal window.-p 3000:3000
: Maps port 3000 on your host to port 3000 in the container.react-app
at the end is the name of the image.http://localhost:3000
to see the React application running inside the Docker
container.
Hurray 🎉. Now we have created and packaged a React app for production use.
js-example-spa
is an example TODO app built with. This project is dockerized and the images are published to Amazon
Elastic Container Registry (ECR).