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

Fix: Update Dockerfile to use correct npm script for frontend service #1020

Merged
merged 3 commits into from
Mar 26, 2024

Conversation

Jeetpal1
Copy link

Description

This pull request addresses the issue found in the frontend Dockerfile where the command npm run local was specified. Since there is no local script in package.json, this command would cause the Docker container to fail to start. I have updated the Dockerfile to execute the dev script instead, which aligns with the existing scripts defined in package.json and ensures that the Docker container for the frontend can start and run without issues.

Related Issues

Steps to Test

  1. Pull down the branch associated with this pull request.
  2. Navigate to the root directory of the project.
  3. Run docker-compose build to rebuild the frontend service with the updated Dockerfile.
  4. Start the services using docker-compose up.
  5. Open a web browser and navigate to http://localhost:3000 to ensure that the frontend service is running and accessible.

Screenshots (if applicable)

N/A (The change is in the configuration file and does not affect the visual aspect of the application.)

Checklist

  • I have tested these changes by rebuilding the Docker container and confirming that the frontend service starts as expected.
  • I have updated the relevant documentation (the Dockerfile) with the correct npm command.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the codebase (updated the Dockerfile CMD instruction).
  • My changes generate no new warnings or errors.
  • The title of my pull request is clear and descriptive (Fix incorrect npm script in Dockerfile for frontend).

This commit addresses an issue in the frontend Dockerfile where the `CMD` directive attempted to execute `npm run local`, a script that doesn't exist in `package.json`. This discrepancy caused the Docker container for the frontend to fail to start, hindering the setup process for developers and contributors working with Docker.

Changes made:
- Updated the `CMD` in the Dockerfile to use `npm run dev -- --host 0.0.0.0`, aligning it with the available scripts defined in `package.json` and ensuring the development server listens on all network interfaces within the Docker container. This adjustment facilitates access to the frontend service from the host machine or other Docker containers.

Verification:
- Rebuilt the Docker image for the frontend and verified that the container starts successfully and is accessible on `http://localhost:3000`.
- Ensured that the frontend application functions as expected when accessed through the browser.

This fix streamlines the developer experience by ensuring the Docker setup process is smooth and aligns with the project's current frontend tooling configuration.
This commit addresses an issue in the frontend Dockerfile where the `CMD` directive attempted to execute `npm run local`, a script that doesn't exist in `package.json`. This discrepancy caused the Docker container for the frontend to fail to start, hindering the setup process for developers and contributors working with Docker.

Changes made:
- Updated the `CMD` in the Dockerfile to use `npm run dev -- --host 0.0.0.0`, aligning it with the available scripts defined in `package.json` and ensuring the development server listens on all network interfaces within the Docker container. This adjustment facilitates access to the frontend service from the host machine or other Docker containers.

Verification:
- Rebuilt the Docker image for the frontend and verified that the container starts successfully and is accessible on `http://localhost:3000`.
- Ensured that the frontend application functions as expected when accessed through the browser.

This fix streamlines the developer experience by ensuring the Docker setup process is smooth and aligns with the project's current frontend tooling configuration.
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is not :
CMD ["npm", "run", "dev"]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @salahlalami,

Thanks for the review! The "--", "--host", "0.0.0.0" part of the command is there to ensure that the development server listens on all network interfaces inside the Docker container. Without it, the server would only be accessible from within the container itself and wouldn't respond to requests from the host machine or other containers. This change ensures that developers can access the frontend service from their local machine when the Docker container is running.

If our Docker setup or Vite's default configuration ensures the server listens on all interfaces without explicitly setting the host, we can certainly simplify the command to just "npm", "run", "dev". I included it for compatibility and accessibility, but I'm open to updating this per your guidance.

@salahlalami salahlalami merged commit db5dcc1 into idurar:master Mar 26, 2024
1 check passed
@salahlalami
Copy link
Member

@Jeetpal1 Thank you

awesomedev82 pushed a commit to awesomedev82/idurar-erp-crm that referenced this pull request May 20, 2024
Fix: Update Dockerfile to use correct npm script for frontend service
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

Successfully merging this pull request may close these issues.

Missing script local in frontend when running with Docker
3 participants