Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Self-start of service in Docker container

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Using the Ubuntu image, after installing Apache2, you need to start Aapche2 as the container starts.

You can't start with the container if you try to modify it in / etc/rc before.

Then write the startup to CMD ["service", "apache2", "start"], and the container cannot be started (because it exits the container after execution) ~

You have to write a self-startup script for apache2 in the container, and then run the script when you start the container, as follows:

# the / bin/bash in the container # vim / ETC _ Apache _ apache2 _ auto _ bin/bash service.shrub _ torque _ bind _ service _ service apache2 start / bin/bash is to keep a terminal, so that the execution will not end. # chmod 777 / etc/apache2/auto_service.sh encapsulates the container with self-startup script as an image # on the server # docker commit demo ubuntu#vim DockerfileFrom demoCMD ["/ bin/sh", "/ etc/apache2/auto_service.sh"] build a new image based on Dockerfile # docker buitd-t auto_apahce2.

After that, use auto_apache2 to image the started container, and then you can start apache2~ automatically.

Of course, you can also write all the steps of self-startup script into Dockerfile:

Dockerfile content

From ubuntu_demoRUN echo-e'#! / bin/sh\ nservice apache2 start\ nbind etc/apache2/auto_service.sh bash'> / etc/apahce2/auto_service.sh & &\ chmod 777 / etc/apache2/auto_service.sh & &\ CMD ["/ bin/sh", "/ etc/apache2/auto_service.sh"]

Generate an image based on Dockerfile

# docker build-t auto_service_ubuntu.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report