tags: docker
docker provides simple commands to manipulate containers. But his command to operate the container does not belong to the system.
Because it is too simple, there must be many shortcomings. For example, startup sequence, dependency check, failed service recovery, etc., all require a mature system service management software to complete.
This article uses redis as an example:
Step 1: Download the mirror
# docker pull docker.io/redis
Step 2: Start the mirror
# docker run -d --name redis_server -p 6379:6379 redis
Step 3: Enter the /etc/systemd/system/ directory and create the docker-container\@.service file
#cd /etc/systemd/system/
#vi /etc/systemd/system/docker-container\@.service
Note: Don't think that docker-container\@.service is missing something, his name is just this.
Copy the following content in
[Unit]
Description=Docker Container %I
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker start -a %i
ExecStop=/usr/bin/docker stop -t 2 %i
[Install]
WantedBy=default.target
Step 4: Set up boot (note: start docker first before booting the container)
# systemctl enable docker.service
# systemctl enable docker-container\@redis_server.service
Step 5: Check whether it can start normally
# systemctl start docker-container\@redis_server.service
# systemctl status docker-container\@redis_server.service
Finally try to restart.
-----------------------------------------------------------------------------------------------------
Self-use
systemctl enable docker-container\@dnmp_mysql.service
systemctl enable docker-container\@dnmp_phpfpm.service
systemctl enable docker-container\@dnmp_nginx.service
You cannot start the service with the service in the docker container of centos7. Error content: Failed to get D-Bus connection: Operation not permitted. Check the information online and say that the ...
1. Install Tomcat image 2. Run the mirror to generate a container 3. View container 4. Enter the container 5. Upload project files in the webapps directory #Copy the host /les/lium/desktop/hello.war f...
Run the CentOS image in Docker, and display the problem that the command cannot be found when using the SystemCTL command Use when running a container The command -in -law container, focusing on -priv...
Author's homepage (Silicon -based workshop of Wenhuo Rock Sugar):Blog of Wenhuo Rock Sugar (Wang Wenbing) URL of this article: Table of contents Foreword: Chapter 1 Install the command of Ubuntu and C...
Solution: Use --Privileged Parameter Initializer...
1. Open the Docker error, as follows 2. Tracking errors to this (many ways to check during the period) 3, see something in the red box box, Docker error when creating file system XFS, so you can know ...
Operating environment Problem Description To deploy mariadb in centos 7.4 container centos-cloudera-1, use systemctl to start mariadb and the prompts are as follows: Solution 1. Create a new container...
lab environment CentOS 7.5 container A container is a running instance of a mirror. The difference is that the image is a static read-only file, and the container has a writable file layer that is req...
This can be solved by: Check the file system /etc/docker/daemon.json to see if there is this file, it is not tested to create it including the secondary directory docker Enter the following in the dae...
The solution to the commands such as SYSTEMCTL cannot be used in the docker container Solution Use service instead of SystemCTL Give privileges and start in init...