Two ways to exit bash in docker container under Linux

Two ways to exit bash in docker container under Linux

If you want to exit bash, there are two options:

The first one:

Ctrl + d to exit and stop the container;

Second type:

Ctrl + p + q to exit and run the container in the background;

Additional knowledge: Docker starts multiple services at the same time

In the previous Docker articles, only one background service was started when starting a container. Today, let’s talk about how to start multiple services through supervisor.

1. First create a directory and create a Dockerfile in the directory. The content of the file is as follows

FROM centos:centos6MAINTAINER Fanbin Kong "[email protected]"RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmRUN yum install -y openssh-server sudo mysql-server mysql supervisorRUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config RUN useradd adminRUN echo "admin:admin" | chpasswdRUN echo "admin ALL=(ALL) ALL" >> /etc/sudoers RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_keyRUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_keyRUN mkdir /var/run/sshdRUN /etc/init.d/mysqld start &&\ mysql -e "grant all privileges on *.* 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/supervisorCOPY supervisord.conf /etc/supervisord.confEXPOSE 22 3306CMD ["/usr/bin/supervisord"]

2. Create the supervisord.conf file in the directory where the Dockerfile is located. The content is as follows:

[supervisord]nodaemon=true[program:sshd]command=/usr/sbin/sshd -D[program:mysqld]command=/usr/bin/mysqld_safe

3. Run the build command in the directory where Dockerfile is located to generate the image file. Here, mysql_server is used as the image file name.

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 it. At this time, you can see that the PORTS column content is

“0.0.0.0:49171->22/tcp, 0.0.0.0:49172->3306/tcp”

The container's ports 22 and 3306 will be mapped to the host machine's ports 49171 and 49172.

4.3 Now you can access the ssh and mysql services through the following commands

ssh admin@<host machine> -p <host machine port>mysql -h <host machine> -u root -pletmein -P 49172

4.4 Of course, you can also use "sudo docker inspect myserver | grep IPAddress" to view the container IP address, and then access the ssh and mysql services through the following commands

ssh admin@<container machine IP> mysql -h <container machine IP> -u root -pletmein

The above two methods to exit bash from docker container under Linux are all the content shared by the editor. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Solve the problem of starting two ports that occupy different ports when docker run
  • Docker uses Supervisor to manage process operations
  • Enable sshd operation in docker

<<:  The presentation and opening method of hyperlink a

>>:  Vue uses drag and drop to create a structure tree

Recommend

About the problem of vertical centering of img and span in div

As shown below: XML/HTML CodeCopy content to clip...

Several common ways to deploy Tomcat projects [tested]

1 / Copy the web project files directly to the we...

17 404 Pages You'll Want to Experience

How can we say that we should avoid 404? The reas...

A simple tutorial on how to use the mysql log system

Table of contents Preface 1. Error log 2. Binary ...

js to realize automatic lock screen function

1. Usage scenarios There is such a requirement, s...

CSS3 realizes the animation effect of lotus blooming

Let’s look at the effect first: This effect looks...

WeChat applet uses the video player video component

This article example shares the specific code of ...

MySQL Server 8.0.3 Installation and Configuration Methods Graphic Tutorial

This document records the installation and config...

Two common solutions to html text overflow display ellipsis characters

Method 1: Use CSS overflow omission to solve The ...

Ubuntu View and modify mysql login name and password, install phpmyadmin

After installing MySQL, enter mysql -u root -p in...

Detailed explanation of the execution process of MySQL query statements

Table of contents 1. Communication method between...

Unicode signature BOM detailed description

Unicode Signature BOM - What is the BOM? BOM is th...

CentOS 7.5 deploys Varnish cache server function

1. Introduction to Varnish Varnish is a high-perf...

Linux installation apache server configuration process

Prepare the bags Install Check if Apache is alrea...

Use of select, distinct, and limit in MySQL

Table of contents 1. Introduction 2. select 2.1 Q...