🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 6 Min Lesezeit
0

A Comprehensive Guide to Dockerfile Creation with Explanation of Key Commands

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Dockerfiles are essential for creating Docker images, which serve as the foundation for containers. These files contain a series of instructions that define the environment in which your application runs. By using a Dockerfile, you ensure your application behaves the same way regardless of where it’s deployed.



Key Dockerfile Instructions and Their Usage



1. FROM – The Base Image

The FROM instruction sets the base image for your Docker image. Every Dockerfile starts with FROM, as it specifies the starting point for your image.



Example:




CODE
FROM node:14






This tells Docker to use the official node:14 image as the base for your image.






2. RUN – Execute Commands



The RUN command is used to execute commands inside the image during the build process. This is typically used to install dependencies or update the image.



Example:




CODE
RUN apt-get update && apt-get install -y curl






This will update the package lists and install curl in your image.






3. MAINTAINER – Image Maintainer Information (Deprecated)



The MAINTAINER instruction was originally used to define the author of the image. However, it’s now deprecated, and it’s recommended to use the LABEL instruction instead for this purpose.



Example:




CODE
MAINTAINER John Doe <[email protected]>









4. LABEL – Metadata



The LABEL instruction adds metadata to an image in the form of key-value pairs. This is useful for providing details about the image, like its version, description, or maintainer.



Example:




CODE
LABEL maintainer="John Doe <[email protected]>"
LABEL version="1.0"









5. ADD – Add Files with Extra Features



The ADD command is used to copy files from your host machine into the container. It also has extra features such as the ability to unpack .tar files or download files from a URL.



Example:




CODE
ADD source.tar.gz /app/






This will copy source.tar.gz from the host and extract it into the /app/ directory in the container.






6. COPY – Copy Files or Directories



COPY works similarly to ADD, but it doesn't have the extra functionality (like automatic extraction of .tar files) and is considered more predictable. You use COPY to copy files or directories into the image.



Example:




CODE
COPY . /app/






This will copy everything from the current directory on your host machine into the /app/ directory in the container.






7. VOLUME – Create Mount Points



The VOLUME command creates a mount point for volumes, which can be used to persist data in a container or share data between containers.



Example:




CODE
VOLUME ["/data"]






This will create a mount point /data, allowing data to persist even if the container is stopped or deleted.






8. EXPOSE – Expose Ports



The EXPOSE command informs Docker that the container will listen on specific ports at runtime. It doesn’t actually publish the port, but it serves as a hint for those who want to map ports when running the container.



Example:




CODE
EXPOSE 8080






This will expose port 8080 on the container, signaling that the container is ready to communicate over this port.






9. WORKDIR – Set Working Directory



WORKDIR sets the working directory for subsequent instructions like RUN, CMD, ENTRYPOINT, COPY, etc. If the directory doesn’t exist, it will be created.



Example:




CODE
WORKDIR /app






This sets /app as the working directory for the following commands.






10. USER – Set User for Container



The USER command sets the user and group to use when running commands inside the container. By default, Docker runs commands as the root user, but it's good practice to specify a non-root user for security.



Example:




CODE
USER node






This sets the user to node when running subsequent commands in the Dockerfile.






11. STOPSIGNAL – Define Stop Signal



The STOPSIGNAL instruction sets the system call signal that will be used to stop the container. By default, Docker uses SIGTERM, but you can specify another signal.



Example:




CODE
STOPSIGNAL SIGINT






This will use the SIGINT signal to stop the container instead of the default SIGTERM.






12. ENTRYPOINT – Set the Entry Point



The ENTRYPOINT command defines the default application that gets executed when a container starts. It’s often used in combination with CMD.



Example:




CODE
ENTRYPOINT ["node", "server.js"]






This will run node server.js as the entry point when the container starts.






13. CMD – Provide Default Arguments



CMD specifies the default command to run when the container is started. It can be overridden when running the container.



Example:




CODE
CMD ["npm", "start"]






This will run npm start by default, unless the command is overridden.



Note: If both ENTRYPOINT and CMD are used together, CMD provides the default arguments for the ENTRYPOINT command.






14. ENV – Set Environment Variables



The ENV instruction is used to set environment variables that will be available to the running container.



Example:




CODE
ENV NODE_ENV production






This sets the NODE_ENV environment variable to production inside the container.









Putting It All Together: A Complete Dockerfile Example



Now that we’ve covered the essential instructions, let’s create a Dockerfile for a basic Node.js application using many of the instructions discussed:






Example Dockerfile:






CODE
# Step 1: Set the base image
FROM node:14

# Step 2: Set the maintainer and other metadata
LABEL maintainer="John Doe <[email protected]>"
LABEL version="1.0"
LABEL description="A simple Node.js app container"

# Step 3: Set the working directory inside the container
WORKDIR /app

# Step 4: Copy package.json and package-lock.json
COPY package*.json ./

# Step 5: Install dependencies
RUN npm install

# Step 6: Copy the rest of the application code
COPY . .

# Step 7: Expose the port the app will run on
EXPOSE 3000

# Step 8: Set the environment variable
ENV NODE_ENV production

# Step 9: Set the default command to run the app
ENTRYPOINT ["node", "server.js"]

# Step 10: Optionally, set the default command arguments (overridden by docker run arguments)
CMD ["start"]

# Step 11: Create a volume to persist data
VOLUME ["/data"]

# Step 12: Set the user to run as non-root
USER node

# Step 13: Define the stop signal for the container
STOPSIGNAL SIGINT









Explanation of the Example:





  1. FROM: We're using the official node:14 image as the base.


  2. LABEL: Metadata is added for versioning and maintainer information.


  3. WORKDIR: All subsequent commands will execute in the /app directory.


  4. COPY: First, we copy package.json to install dependencies, then copy the application code.


  5. RUN: Installs Node.js dependencies using npm install.


  6. EXPOSE: Exposes port 3000 to allow communication with the outside world.


  7. ENV: Sets the NODE_ENV to production.


  8. ENTRYPOINT: Defines the main application start command.


  9. CMD: Provides default arguments to the entrypoint command (in this case, start).


  10. VOLUME: Creates a volume at /data for data persistence.


  11. USER: Switches to the node user for better security.


  12. STOPSIGNAL: Sets SIGINT as the stop signal, which is often used for graceful shutdowns.









Conclusion



Dockerfiles provide a powerful and flexible way to automate the creation of Docker images, ensuring that your applications are portable, reproducible, and easy to deploy. By understanding each Dockerfile instruction like FROM, RUN, LABEL, COPY, ENTRYPOINT, CMD, and others, you can build optimized, secure, and scalable images for your applications.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten A Comprehensive Guide to Dockerfile Creation with Explanation of Key Commands

Thematisch verwandte Begriffe: Comprehensive, Guide, Dockerfile, Creation · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...