Docker Security Scanner
Scan your Dockerfile for security vulnerabilities and best practices. Get recommendations to improve the security of your Docker images.
Security Analysis Results
Scan Summary
Identified Issues
-
Running as root userCritical
Your Dockerfile does not specify a non-root user, which means the container will run as root by default. Running containers as root is a security risk because if an attacker breaks out of the container, they would have root privileges on the host.
FROM ubuntu:20.04 RUN apt-get update && apt-get install -y nodejs npm WORKDIR /app COPY . . RUN npm install EXPOSE 3000 CMD ["npm", "start"]Recommended Fix:FROM ubuntu:20.04 RUN apt-get update && apt-get install -y nodejs npm WORKDIR /app COPY . . RUN npm install # Create a non-root user RUN groupadd -r nodejs && useradd -r -g nodejs nodejs # Set ownership of application files RUN chown -R nodejs:nodejs /app # Switch to non-root user USER nodejs EXPOSE 3000 CMD ["npm", "start"]This fix creates a dedicated non-root user and group, then sets the appropriate ownership on your application files before switching to that user for running the container. This limits the potential impact of a container breakout vulnerability.
-
Using latest/default tag for base imageHigh
Your Dockerfile uses a base image with a non-specific version (20.04). While this does specify a major version, it doesn't pin to a specific minor version or digest, which can lead to unexpected changes when the base image is updated.
FROM ubuntu:20.04Recommended Fix:FROM ubuntu:20.04@sha256:80ef4a44043dec4490506e6cc4289eeda2d106a70fe32ef29cce1b1db48c2aadThis fix pins the base image to a specific digest, ensuring your builds use exactly the same base image every time, preventing unexpected changes or vulnerabilities from newer images.
-
No .dockerignore file detectedHigh
Your Dockerfile uses a COPY . . instruction, but no .dockerignore file was detected. This can lead to sensitive files being included in your Docker image, such as git history, environment files, or secrets.
COPY . .Recommended Fix:Create a .dockerignore file in your project with at minimum the following content:
.git .gitignore node_modules npm-debug.log .env .env.* *.log *.md .dockerignore Dockerfile*Using a .dockerignore file prevents sensitive files from being copied into your Docker image, reducing the risk of secrets exposure and decreasing image size.
Learn More: -
Not clearing package manager cacheMedium
Package manager cache files remain in the image, increasing image size unnecessarily and potentially including package indexes that may contain vulnerabilities.
RUN apt-get update && apt-get install -y nodejs npmRecommended Fix:RUN apt-get update && \ apt-get install -y nodejs npm && \ apt-get clean && \ rm -rf /var/lib/apt/lists/*This fix ensures package manager cache files are cleaned up in the same layer where packages are installed, reducing image size and potential attack surface.
Suggested Secured Dockerfile
Want to Learn More About Docker Security?
Check out our detailed tutorials on Docker security best practices, including securing your images, implementing least privilege, and scanning for vulnerabilities.
Browse Security Tutorials