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

Detailed installation and use tutorial of mysql 8.0.15 under windows

This article shares with you the detailed install...

Detailed explanation of CSS label mode display property

The code looks like this: <!DOCTYPE html> &...

How to monitor Windows performance on Zabbix

Background Information I've been rereading so...

How to connect to MySQL visualization tool Navicat

After installing Navicat The following error may ...

Example code of javascript select all/unselect all operation in html

Copy code The code is as follows: <html> &l...

Vue's Render function

Table of contents 1. Nodes, trees, and virtual DO...

vue-cli4.5.x quickly builds a project

1. Install vue-cli npm i @vue/cli -g 2. Create a ...

JS gets the position of the nth occurrence of a specified string in a string

Learn about similar methods for getting character...

Detailed use cases of vue3 teleport

Official Website https://cli.vuejs.org/en/guide/ ...

Example steps for using AntV X6 with Vue.js

Table of contents 0x0 Introduction 0x1 Installati...

Mysql sorting to get ranking example code

The code looks like this: SELECT @i:=@i+1 rowNum,...

Are the value ranges of int(3) and int(10) the same in mysql

Table of contents Question: answer: Reality: Know...

Complete steps to build a squid proxy server in linux

Preface This article mainly introduces the releva...

Install Python virtual environment in Ubuntu 18.04

For reference only for Python developers using Ub...

How to transfer files between Windows and Linux

File transfer between Windows and Linux (1) Use W...