Multi-service image packaging operation of Dockerfile under supervisor

Multi-service image packaging operation of Dockerfile under supervisor

Writing a Dockerfile

Configure yum source

cd /tmp/docker
vim Dockerfile
FROM rhel7
EXPOSE 80 22 # Expose ports 80 and 22 to the outside world COPY dvd.repo /etc/yum.repos.d/dvd.repo
&& yum install -y httpd openssh-server openssh-clients supervisor
&& yum clean all 
&& ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" 
&& ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ed25519_key -N "" 
&& echo root:redhat | chpasswd
COPY supervisord.conf /etc/supervisord.conf
CMD ["/usr/bin/supervisord"]
vim supervisord.conf
[supervisord]
nodaemon=true

[program:sshd]
command=/usr/sbin/sshd -D

[program:httpd]
command=/usr/sbin/httpd
docker build -t rhel7:v3
Sending build context to Docker daemon 8.192 kB
Step 1/6: FROM rhel7
 ---> 0a3eb3fde7fd
Step 2/6: EXPOSE 80 22
 ---> Running in 5727c9e984a5
 ---> e25a8a0821f7
Removing intermediate container 5727c9e984a5
Step 3/6 : COPY dvd.repo /etc/yum.repos.d/dvd.repo
 ---> 2d9e8f9648a7
Removing intermediate container 62955f7a7a74
Step 4/6 : RUN rpmdb --rebuilddb && yum install -y httpd openssh-server openssh-clients supervisor && yum clean all && ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N "" && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ed25519_key -N "" && echo root:redhat | chpasswd
Dependency Updated:
 elfutils-libelf.x86_64 0:0.166-2.el7                     

Complete!
Skipping unreadable repository '///etc/yum.repos.d/rhel7.repo'
Cleaning repos: docker dvd-rhel
Cleaning up everything
 ---> 1cb2f9e34bac
Removing intermediate container 33cb452dbc8d
Step 5/6 : COPY supervisord.conf /etc/supervisord.conf
 ---> e8de2ff5ca3c
Removing intermediate container f219cb2b6a88
Step 6/6 : CMD /usr/bin/supervisord
 ---> Running in eddfb3973ad2
 ---> dbf4cf5cb116
Removing intermediate container eddfb3973ad2
Successfully built dbf4cf5cb116

docker run -d --name vm1 -v /tmp/docker/web/:/var/www/html rhel7:v3

docker ps

docker inspect vm1
      "Networks": {
        "bridge": {
          "IPAMConfig": null,
          "Links": null,
          "Aliases": null,
          "NetworkID": "126902125dd9c54631622845c1a75d656b45023840c57944ec24f4acecf6dc3f",
          "EndpointID": "3d995f01fce91968f59b151a19ba3868292efe0a61c2ef355bcd1eb84bda7248",
          "Gateway": "172.17.0.1",
          "IPAddress": "172.17.0.2", # container's IP
          "IPPrefixLen": 16,
          "IPv6Gateway": "",
          "GlobalIPv6Address": "",
          "GlobalIPv6PrefixLen": 0,
          "MacAddress": "02:42:ac:11:00:02"
        }
      }

verify:

curl 172.17.0.2

Verify the sshd service:

Supplementary knowledge: Use Dockerfile to build a supervisor container deployment project, CMD ["supervisord","-c","/etc/supervisord.conf"] execution failed

Problem description:

When writing a Dockerfile to create a supervisor container, the last command to start supervisor does not work -> CMD ["supervisord","-c","/etc/supervisord.conf"], but executing supervisord -c /etc/supervisord.conf inside the container can run successfully.

First paste the Dockerfile file code

FROM python:latest 
WORKDIR /root/
 
RUN mkdir /etc/supervisor
RUN mkdir -p /root/projects/logs/gunicorn/
RUN mkdir -p /root/projects/logs/celery/
RUN mkdir -p /root/projects/Sy_EvaluateJkApi/logs/
RUN echo "deb http://mirrors.aliyun.com/debian/ buster main non-free contrib" > /etc/apt/sources.list
RUN echo "deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/debian-security buster/updates main" >> /etc/apt/sources.list
RUN echo "deb-src http://mirrors.aliyun.com/debian-security buster/updates main" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib" >> /etc/apt/sources.list
RUN echo "deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib" >> /etc/apt/sources.list
RUN echo "deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib" >> /etc/apt/sources.list
RUN apt-get update -y
RUN apt-get install -y git lrzsz vim
RUN pip install supervisor -i https://mirrors.aliyun.com/pypi/simple/
RUN pip install gunicorn -i https://mirrors.aliyun.com/pypi/simple/
RUN pip install gevent -i https://mirrors.aliyun.com/pypi/simple/
RUN /usr/local/bin/echo_supervisord_conf > /etc/supervisord.conf
RUN echo "[include]">>/etc/supervisord.conf
RUN echo "files = /etc/supervisor/*.ini">>/etc/supervisord.conf
 
ADD sy.ini /etc/supervisor/sy.ini
ADD Sy_EvaluateJkApi /root/projects/Sy_EvaluateJkApi
RUN pip3 install -r /root/projects/Sy_EvaluateJkApi/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
EXPOSE 8800
CMD ["supervisord","-c","/etc/supervisord.conf"]

There is no exception when building the container image using the docker build -t system:test . command, but running the container using docker run -itd system:test shows that the container is not running.

Solution:

Change the command CMD ["supervisord","-c","/etc/supervisord.conf"] to CMD ["supervisord","-n","-c","/etc/supervisord.conf"] and it will run successfully.

This is what is written in supervisor -n/--nodaemon -- run in the foreground (same as 'nodaemon=true' in config file). Adding -n allows supervisor to keep running in the foreground.

The above multi-service image packaging operation of Dockerfile under supervisor is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Steps to build a Docker image using Dockerfile
  • How to create Apache image using Dockerfile
  • Docker image creation Dockerfile and commit operations
  • How to build a tomcat image based on Dockerfile
  • How to customize Docker images using Dockerfile
  • Detailed explanation of Dockerfile to create a custom Docker image and comparison of CMD and ENTRYPOINT instructions
  • Implementation of tomcat image created with dockerfile based on alpine
  • Implementation of crawler Scrapy image created by dockerfile based on alpine
  • How to create your own image using Dockerfile
  • Build a Docker image using Dockerfile

<<:  Understanding innerHTML

>>:  Two solutions for automatically adding 0 to js regular format date and time

Recommend

Docker network mode and configuration method

1. Docker Network Mode When docker run creates a ...

How to reasonably use the redundant fields of the database

privot is the intermediate table of many-to-many ...

A brief analysis of the knowledge points of exporting and importing MySQL data

Often, we may need to export local database data ...

Summary of how to modify the root password in MySQL 5.7 and MySQL 8.0

MySQL 5.7 version: Method 1: Use the SET PASSWORD...

Detailed explanation of the abbreviation of state in react

Preface What is state We all say that React is a ...

How to create components in React

Table of contents Preface Component Introduction ...

Two ways to open and close the mysql service

Method 1: Use cmd command First, open our DOS win...

Mysql database recovery actual record by time point

Introduction: MySQL database recovery by time poi...

Complete steps to implement location punch-in using MySQL spatial functions

Preface The project requirement is to determine w...

How to smoothly go online after MySQL table partitioning

Table of contents Purpose of the table For exampl...

OpenLayers realizes the method of aggregate display of point feature layers

Table of contents 1. Introduction 2. Aggregation ...

Super detailed basic JavaScript syntax rules

Table of contents 01 JavaScript (abbreviated as: ...

JS cross-domain solution react configuration reverse proxy

Cross-domain solutions jsonp (simulate get) CORS ...

How to bind Docker container to external IP and port

Docker allows network services to be provided by ...