Docker File
Image Environment Blueprint | Dockerfile |
---|---|
Install Node | FROM node |
Set environment variables: MONGO_DB_USERNAME=admin MONGO_DB_PWD=password | ENV MONGO_DB_USERNAME=admin \ MONGO_DB_PWD=password |
Layers in Docker Image
Whenever a change in the filesystem is made, such as adding or modifying files, a layer is created.
A layer is a snapshot of the file system after running a command in the Dockerfile.
- Stacked on top of each other to form an image
- Immutable. If a change is made in the docker file, a new layer will be created.
- Building blocks of Docker images
What is the difference between RUN and CMD?
RUN | CMD |
---|---|
Used to execute commands during the image build process. | Specifies the default command to run when a container starts. |
ENTRYPOINT vs. CMD
- CMD can be overridden at runtime (docker run myimage my_new_command).
- ENTRYPOINT makes the command fixed (useful for predefined startup scripts).
To build a new image from a Docker file
docker build -t <ImageName>:<version> <dockerfile_path>
Example: docker build -t my-app:1.0 dockerfile_path
Docker Compose
- Simplifies container management
- Helps to structure your commands
- Defines the desired state
- By default, sets up a single network for all services in the file
- docker-compose -f file.yaml up – runs the file
- docker-compose -f file.yaml down – stops all containers and removes the network