Some important information about Docker container
Partho Das
I help businesses design and automate their cloud infrastructure, streamline software deployment pipelines, and ensure they scale efficiently and securely.
What is docker container and what is K8s Pod
What are the ways, we can troubleshoot issues related to docker Containers.
How to delete unused docker resources like
How to know which network does not have any containers attached.
#!/bin/bash
# List all networks
for network in $(docker network ls -q); do
# Check if the network has no containers attached
if [ -z "$(docker network inspect -f '{{.Containers}}' $network | grep -v '{}')" ]; then
echo "Pruning network $network which has no containers attached."
docker network rm $network
fi
done
How to restrict a container to have 1 CPU & 1GB Ram
docker run -d --cpu 1 --memory 1g --name partho-container nginx
In the docker file, what is the difference between run & cmd
Basic Dockerfile
# Use the official Nginx base image
FROM nginx:latest
# Set the working directory in the container
WORKDIR /usr/share/nginx/html
# Copy the content of the current directory to the container
COPY . .
# Expose port 80 to the host
EXPOSE 80
# The default command to run when the container starts
CMD ["nginx", "-g", "daemon off;"]
Multistage Dockerfile
领英推荐
# Stage 1: Build
FROM node:16-alpine AS build
# Set the working directory
WORKDIR /app
# Copy the package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
# Build the React application
RUN npm run build
# Stage 2: Run
FROM nginx:alpine
# Copy the built React application from the build stage
COPY --from=build /app/build /usr/share/nginx/html
# Expose port 80
EXPOSE 80
# Start nginx
CMD ["nginx", "-g", "daemon off;"]
Update the Docker container without Data-loss to a new image
How to move one container from one Host-1 to Host-2
How to Restore a container from Backup?
How to ensure the containers are secure?
What are the best practices of Docker as a Container.
Docker Volume is also very essential to retain the data in a container, because its a limitation of container as it does not have any native solution to have any storage.
I will write another article on Docker volume which overcomes the limitations of container storage.