如何在Mac本地运行shakyshane/cra-docker Docker镜像?
The shakyshane/cra-docker image you’re trying to pull is either no longer available on Docker Hub or is a private repository you don’t have access to. Since you already cloned the reference code repo locally, we can build the Docker image directly from your local files instead—here’s how:
1. Navigate to your cloned repo directory
Open your terminal and switch to the root folder of the GitHub repo you cloned:
cd /path/to/your/cloned/react-repo
2. Verify the Dockerfile exists
Check that there’s a Dockerfile in the root directory (the tutorial’s containerized app should include this). If for some reason it’s missing, you can use this standard Dockerfile for Create React App projects:
# Build stage FROM node:18-alpine as build WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build # Serve stage FROM nginx:alpine COPY --from=build /app/build /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
3. Build your local Docker image
Run this command to build an image from the Dockerfile, naming it something like my-local-cra-app (you can use any name you want):
docker build -t my-local-cra-app .
This will install dependencies, build your React app, and package everything into a runnable Docker image.
4. Start the container from your built image
Once the build finishes, launch the container and map your local port 8080 to the container’s port 80:
docker run -p 8080:80 my-local-cra-app
5. Test the app
Open your browser and go to http://localhost:8080—you should see your React app running!
Quick Notes
- The reason
npm startdidn’t work is because containerized React apps are designed to run from a production build served by a web server (like Nginx in the Dockerfile), not the Node development server. You’d need to runnpm installfirst if you wanted to use the dev server, but building the Docker image is the intended workflow here. - If you hit issues during the build (like dependency errors), try deleting any local
node_modulesorpackage-lock.jsonfiles before re-running the build command, or check that the Node version in the Dockerfile matches what the repo expects.
内容的提问来源于stack exchange,提问作者Mr.X

