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

Explanation of the basic syntax of Mysql database stored procedures

drop procedure sp_name// Before this, I have told...

Linux installation MySQL tutorial (binary distribution)

This tutorial shares the detailed steps of instal...

JQuery implements hiding and displaying animation effects

This article shares the specific code of JQuery t...

6 inheritance methods of JS advanced ES6

Table of contents 1. Prototype chain inheritance ...

How to set up virtual directories and configure virtual paths in Tomcat 7.0

Tomcat7.0 sets virtual directory (1) Currently, o...

Summary of common docker commands (recommended)

1. Summary: In general, they can be divided into ...

How to configure nginx to limit the access frequency of the same IP

1. Add the following code to http{} in nginx.conf...

Create a movable stack widget function using flutter

This post focuses on a super secret Flutter proje...

Why Use DOCTYPE HTML

You know that without it, the browser will use qui...

HTML Tutorial: Collection of commonly used HTML tags (4)

Related articles: Beginners learn some HTML tags ...

Summary of Kubernetes's application areas

Kubernetes is the leader in the container orchest...

Detailed explanation of this pointing problem in JavaScript

Preface The this pointer in JS has always been a ...

HTML+CSS merge table border sample code

When we add borders to table and td tags, double ...

Use of Linux sed command

1. Function Introduction sed (Stream EDitor) is a...