Hongmu Notes

Container named parameters

Only after the name is clear can the log and terminal be found.
100% Browser local processing 0 Data upload

🐳 Command assembly

💡 Instructions for use

  • The port and directory are written as "host on the left, container on the right". If they are written backward, the service will start successfully but cannot be accessed, or the original file in the container will be overwritten.
  • The data directory must be mounted; unmounted directories will disappear when the container is deleted. Pay special attention to databases and uploaded files.
  • It is recommended to choose the automatic restart strategy for long-running services. The container can recover on its own after abnormal exit, reducing manual intervention.
  • The command is output in a single line, making it easy to paste directly into the terminal; when there are many parameters, it is recommended to record them in the deployment script together with the parameters.

Only after the name is clear can the log and terminal be found.

The problem of not naming

If you do not specify a name, the system will generate a random name, making it difficult to distinguish when there are too many containers.

To view the logs and enter the container later, you must first find out the name, which is an extra step.

Naming convention

The name needs to be unique, usually a combination of project name plus role plus serial number.

Using only simple words can easily conflict between multiple projects.

name conflict

Reusing an existing name will directly report an error and needs to be deleted or renamed first.

When rebuilding a container, first stop and delete the old container, and then create it with the original name.

relationship with numbers

Both the name and the system-assigned number can be used to specify the container, making the name easier to remember.

Longer numbers are suitable for use in scripts to avoid ambiguity.

Batch management

If the names are regular, you can use prefix matching to view and operate them in batches.

After standardized naming, containers in logs and monitoring can be more easily mapped to specific services.

The name must be unique. It is recommended to use the project name plus role plus serial number; delete the old container before rebuilding.

📖 Glossary

container
The running instance started by the image has an independent file system and network view. Deleting the container does not affect the image itself. Whether the data is retained depends on whether the external directory is mounted.
mirror
The read-only template based on which the container is started includes programs and dependencies; labels are used to distinguish different versions of the same image. If no label is written, the latest version will be taken by default. It is easy for environment changes to occur due to pulling in a new version.
Running in the background
Let the container execute in the background, and the command returns immediately and outputs the container ID. Without this option, the container's log will occupy the terminal, and the container will exit when the terminal is closed.
port mapping
Forward the host's port to the container's internal port, which is written as "host port:container port". Without mapping, services in the container can only be accessed within the container network.
Directory mount
Map the host directory or data volume to the path in the container so that the data will be retained after the container is rebuilt, and it will also be convenient to view and back up files directly on the host.
environment variables
Configuration items passed to the process in the container in the form of key-value pairs are often used to set the database address, operating mode, and initial password to avoid hard-coding the configuration in the image.
Restart strategy
Defines whether and how the container automatically restarts after exiting. The options are no restart, restart on failure, always restart, and restart unless manually stopped. The last one is commonly used in production environments.
Resource limits
Limit the upper limit of processors and memory that can be used by containers to prevent a single container from occupying host resources and affecting other services. When setting the upper memory limit, it is recommended to match the actual needs of the program.
Build context
The directory range sent to the build engine when building an image. The copy instructions in the build file can only reference files within this range. If the range is too large, it will be slow and may leak irrelevant files.
Build cache
The build engine reuses the last results for unchanged steps, which can significantly speed up the build; when dependencies encounter exceptions or require a new build, you can choose not to use caching.
container network
A virtual network used for communication between containers. Containers in the same network can access each other by name, so multi-service deployments often put related containers into the same custom network.
Enter the container
Open a terminal in the running container to troubleshoot the problem. You should actively exit after troubleshooting. Temporarily installed tools and changes will disappear when the container is rebuilt and are not suitable for formal modification.

🔗 All keywords and tutorials

Keywords page of the tool12a

Return to tool home page

❓ FAQ

What happens if the name is duplicated?
An error will be reported directly when creating it. You need to stop and delete the old container with the same name first, or change the name.
Which one is more useful, name or number?
The name is easy to remember and suitable for daily operations; the number is unique and suitable for scripts and automation scenarios.