Docker Notes
Docker Notes
Docker Notes
FROM openjdk:17-jdk-alpine
#Working Directory
WORKDIR app/
#Code
#Libraries
#RUN
CMD ["java","Main"]
fi
To delete all running and exited containers in a single command, you can use:
Explanation:
• docker ps -aq: Lists the container IDs of all containers (both running and exited).
• docker rm -f: Removes containers, and the -f option forces removal of running
containers.
This command will stop and delete all containers on your system. Use it with caution if you
want to keep any data from those containers.
In Docker, the difference between a named volume and an unnamed (or bind) volume lies in
how they are managed and where they are stored:
1. Named Volume
Portability More portable (Docker handles path) Less portable (host path is required)
Use Case Persistent, managed storage (e.g., databases) Access to speci c host data
Flexibility Less exible in choosing storage location More exible (direct control over path)
Both types of volumes are useful in different scenarios, depending on whether you need a consistent, Docker-managed
volume or direct access to host les.
Docker network ls
• test: Speci es the command to check if the MySQL server is up. The command here is:
mysqladmin ping -h localhost -uroot -padmin
• This command:
◦ Uses mysqladmin ping to send a ping request to the MySQL server on localhost.
◦ -uroot: Speci es the username root.
◦ -padmin: Speci es the password as admin (password of the root user, as set in
MYSQL_ROOT_PASSWORD).
◦ If MySQL responds with mysqld is alive, the health check passes; otherwise, it fails.
• interval: De nes the time between each health check attempt. Here, Docker will perform a health check
every 10 seconds.
• timeout: Sets the maximum time Docker will wait for a response before marking the check as failed.
Here, it’s set to 20 seconds.
• retries: Speci es how many times Docker will retry the health check before marking the container as
unhealthy if the checks continue to fail. In this case, Docker will retry up to 10 times before
declaring the container unhealthy.
• start_period: Sets the initial wait time before Docker starts performing health checks. Here, Docker will
wait 60 seconds after the container starts before beginning the health checks. This delay is helpful
for services like MySQL that take a bit longer to fully start up.
Summary
This health check will make Docker wait for 60 seconds after the container starts, then it will ping MySQL
every 10 seconds with a 20-second timeout. If MySQL is unresponsive 10 times in a row, the container will be
marked as unhealthy.
fi
fi
fi
fi
fi