Install Docker
Docker Swarm
Docker Concept
Docker compose
Docker command
Network in Docker
Docker Volume
The RUN instruction is used to execute commands during the build process of a Docker image
The CMD instruction is used to specify the default command that should be executed when a container is run based on the image
COPY is a straightforward instruction for copying files and directories from the host to the image, while ADD has additional functionality for extracting compressed files and downloading files from URLs
ADD archive.tar.gz /app/
ADD https://example.com/file.txt /app/file.txt
The COPY instruction is preferred when you simply need to copy files from the host to the image and don’t require any complex extraction or additional operations.
To summarize, the main differences between ENTRYPOINT and CMD are:
ENTRYPOINTsets the primary command for the container, and it cannot be easily overridden.CMDprovides default arguments for theENTRYPOINTcommand or specifies the command to be executed if noENTRYPOINTis specified. It can be overridden when running the container.
FROM python:3.9
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
In this example, the CMD instruction specifies the default argument for the ENTRYPOINT command. So, when the container starts, the primary command executed will be python app.py because the ENTRYPOINT command is python and the CMD instruction provides app.py as the default argument.
Build context
In Docker Compose, the profiles feature allows you to define and manage different sets of services or configurations for your application. With profiles, you can selectively enable or disable specific services, volumes, networks, or other settings based on your needs. Profiles allow you to manage different configurations easily and switch between them based on your requirements. They are particularly useful when you have multiple environments like development, production, testing, and you need to enable or disable specific services or configurations depending on the environment you’re working with.