Docker Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Docker Notes

Docker File Sample


rm -v Docker le
#OS with Env (base image)

FROM openjdk:17-jdk-alpine

#Working Directory

WORKDIR app/

#Code

COPY src/Main.java Main.java

#Libraries

RUN javac Main.java

#RUN

CMD ["java","Main"]
fi
To delete all running and exited containers in a single command, you can use:

docker rm -f $(docker ps -aq)


docker rmi -f $(docker images -aq)

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

• Created and managed by Docker.


• Stored in Docker's default location, typically at /var/lib/docker/volumes on
the host system.
• Useful for persistent data because Docker handles the path, making it more portable and
easier to manage across different environments.
• Created using docker volume create or by specifying a volume name in the

2. Unnamed (Bind) Volume

• Maps a speci c directory on the host system to a directory in the container.


• Requires you to specify the full path on the host, making it less portable since the path may vary
between different systems.
• Provides more direct control over where data is stored and allows sharing directories between
host and container.
• Example:
fi
Aspect Named Volume Unnamed (Bind) Volume

Path Docker-managed (/var/lib/docker/volumes/...) Host-de ned directory

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

Docker network create -d bridge twitter

Docker compose : a yaml le


Package docker compose uses v2
But syntax is 3.8
fl
fl
fi
fi
fi
fi
This healthcheck section in Docker Compose is used to monitor the health of the MySQL container by
periodically checking if MySQL is running and responsive. Here’s a breakdown of each part:

• 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy