Redhat Linux 9 Lab: Bổ sung biến môi trường cho container, ví dụ trường hợp chạy MariaDB hoặc MySQL
Link playlist
Red Hat Enterprise Linux Administration
2024 01 08 03 52 01
Managing Container Environment Variables
Many containers can be started without providing any additional information.
Some containers need further specification of how to do their work. This
information is typically passed using environment variables. A well-known
example where you have to pass environment variables to be able to run the
container successfully is mariadb, the database service that needs at least to
know the password for the root user that it is going to use.
If a container needs environment variables to do its work, there are a few ways
to figure this out:
Just run the container without any environment variables. It will
immediately stop, and the main application will generate an error message.
Use podman logs on your container to read the log for information on what
went wrong.
Use podman inspect to see whether there is a usage line in the container
image that tells you how to run the container. This may not always work, as
it depends on whether or not the image creator has included a usage line in
the container image.
After you’ve found out how to run the container, run it, specifying the
environment variables with the -e option. To run a mariadb instance, for
example, you can use podman run -d -e
MYSQL_ROOT_PASSWORD=password -e MYSQL_USER=anna -e
MYSQL_PASSWORD=password -e MYSQL_DATABASE=mydb -p
3306:3306 mariadb. Exercise 26-6 guides you through the procedure of
running a container using environment variables.
Exercise 26-6 Managing Container Environment Variables
1. Use podman run docker.io/library/mariadb. It will fail (and you will see
an error message on the STDOUT).
2. Use podman ps -a to see the automatically generated name for the failing
mariadb container.
3. Use podman logs container_name to see the Entrypoint application error
log. Make sure to replace container_name with the name you found in step
2.
4. Use podman inspect mariadb and look for a usage line. You won’t see
any.
5. Use podman search registry.redhat.io/rhel9/mariadb to find the exact
version number of the mariadb image in the RHEL registry.
6. Use podman login registry.redhat.io and provide valid credentials to log
in.
7. Use podman run registry.redhat.io/rhel9/mariadb-nnn (make sure to
replace nnn with the version number you found in step 5). It will also fail
but will show much more usage details on the STDOUT. The reason is that
the Red Hat mariadb image is not the same as the image that was fetched
from the Docker registry in the first step of this procedure.
8. Use podman inspect registry.redhat.io/rhel9/mariadb-nnn and in the
command output search for the usage line. It will tell you exactly how to
run the mariadb image.
9. According to the instructions that you found here, type podman run -d -e
MYSQL_USER=bob -e MYSQL_PASSWORD=password -e
MYSQL_DATABASE=mydb -e
MYSQL_ROOT_PASSWORD=password -p 3306:3306
registry.redhat.io/rhel9/mariadb-105. (By the time you read this, the
version number may be different, so make sure to check the version number
of the image if you’re experiencing a failure in running this command.)
10. Use podman ps. You will see the mariadb container has now been started
successfully.
[ad_2]
source