Docker how to start multiple services at the same time _docker

Source: Internet
Author: User
Tags mkdir ssh docker ps docker run

A few Docker articles about starting a container are only starting a background service, today to say how to start multiple services through supervisor

1. First create a directory and create a dockerfile in the directory, the contents of the file are as follows

 from CENTOS:CENTOS6 maintainer fanbin Kong "kongxx@hotmail.com" RUN RPM-IVH http://dl . fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm RUN Yum install-y openssh-server sudo mysql-server MySQL supervisor run sed-i ' s/usepam yes/usepam no/g '/etc/ssh/sshd_config run useradd admin RUN Echo ' admin:admin ' | CHPASSWD run echo "admin all= (All)" >>/etc/sudoers run ssh-keygen-t dsa-f/etc/ssh/ssh_host_dsa_key run SS H-keygen-t rsa-f/etc/ssh/ssh_host_rsa_key RUN mkdir/var/run/sshd run/etc/init.d/mysqld start &&\ mysql-e " Grant all privileges in *.* to ' root ' @ '% ' identified by ' letmein '; &&\ MYSQL-E "Grant all privileges on *.* to ' root ' @ ' localhost ' identified by ' letmein ';"

&&\ mysql-u root-pletmein-e "show databases;"

RUN mkdir-p/var/log/supervisor COPY supervisord.conf/etc/supervisord.conf expose 3306 CMD ["/usr/bin/supervisord"] 

2. Create the supervisord.conf file in the Dockerfile directory, as follows:

[Supervisord]
Nodaemon=true
[program:sshd]
command=/usr/sbin/sshd-d
[program:mysqld]
command=/usr/bin/mysqld _safe


3. Run build command in Dockerfile directory to generate image file, use Mysql_server as image filename

sudo docker build-t myserver.

4. Start the container

4.1 First Use the following command to start the container

sudo docker run--name=myserver-d-p myserver

4.2 After starting the container, you can use "sudo docker ps" To view, you can see the Ports column content as
"0.0.0.0:49171->22/tcp, 0.0.0.0:49172->3306/tcp."
The container's 22 and 3306 ports are mapped to the host machine's 49171 and 49172 ports.

4.3 The ssh and MySQL services can be accessed at this time by using the following commands

SSH admin@< host machine >-P < host machine ports >
Mysql-h < host machine >-u root-pletmein-p 49172

4.4 Of course you can also use the sudo docker inspect myserver | grep ipaddress to view the container IP address, and then access the SSH and MySQL services by following the command

SSH admin@< container Machine ip>
Mysql-h < container machine ip>-u Root-pletmein

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.