Skip to main content

Posts

Showing posts with the label Docker

RUN and CMD instructions in Docker

In Docker, the RUN and CMD instructions serve different purposes, primarily relating to when and how commands are executed within the container lifecycle. RUN Instruction : Purpose : The RUN command is used to build the image. It executes the specified command(s) and commits the result to the image, so the changes become part of the image layers. Execution Time: During the build phase of the Docker image. Use Case : Commonly used for installing software, setting up files, or configuring the environment. RUN apt-get update && apt-get install -y nginx Here, RUN installs nginx in the image. When the image is built, the installed software is included in the image. CMD Instruction : Purpose : The CMD command provides default instructions for the container. It defines what should be executed when a container starts. Execution Time: At container runtime (when the container is launched from the image). Use Case : Typically, used to specify the main application or command to ...

Docker - Basic Details

Docker is an advanced  OS virtualization  software  platform  that makes it easier to create, deploy, and run applications in a Docker container. Docker is a container management service. The keywords of Docker are  build, ship  and  run  anywhere. The whole idea of Docker is for developers to easily develop applications, ship them into containers which can then be deployed anywhere.  Docker allows the developers to choose the project-specific deployment environment for each project with a different set of tools and application stacks. Docker provides flexibility and portability to run an application in various locations, whether on-premises or in a public cloud or a private cloud. Features of Docker Docker has the ability to reduce the size of development by providing a smaller footprint of the operating system via containers. With containers, it becomes easier for teams across different units, such as development, QA and Operations to work ...

Difference between ADD and COPY in Dockerfile

In a Dockerfile, both ADD and COPY are used to copy files or directories from the source on the host machine to the image.  However, they have some key differences: Basic Functionality : COPY : A straightforward command for copying files or directories from the source (host) into the container image. ADD : Does everything that COPY does but with additional functionalities. Additional Features in ADD : Automatic Extraction of Archives : ADD can automatically unpack compressed files (e.g., .tar , .tar.gz , .tar.bz2 ) into the container. This feature is not available with COPY . Remote URL Support : ADD allows you to specify a URL as the source, downloading the file directly into the container. COPY only supports local files and directories. When to Use : COPY is generally preferred for simple file or directory copying tasks because it’s more explicit and doesn't introduce unintended behaviors like auto-extraction or downloading. ADD is more appropriate when you specifically n...

Best Practices for Docker

In Software industry, there are several challeneges coming during development,deployment and scaling time. Here, Docker is coming to solve many of these challenges by creating consistent, isolated environments for applications.  By following some of the best practices, we can create more efficient, secure, and maintainable Docker images and containers that work well in any environment.  Here are some key best practices for working with Docker, especially in multi-environment and production settings: 1. Optimize Dockerfile and Images Use Small Base Images : Start with a small, minimal base image, like alpine , when possible, to reduce your image size. Minimize Layers : Each instruction in a Dockerfile creates a new layer. Combining commands (e.g., RUN apt-get update && apt-get install -y package ) reduces the number of layers. Leverage Multistage Builds : Use multiple stages in your Dockerfile to separate the build and production environments. This allows you to in...