[root@localhost ~]# docker run -tid --name nginx centos
4fc4c145ed73916c7893e39837a5a04b3fbbc18dba0cf09f85c9e4f4efb588c1
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4fc4c145ed73 centos "/bin/bash" About a minute ago Up About a minute nginx
[root@localhost ~]# docker exec -it 4fc4c145ed73 /bin/bash
[root@4fc4c145ed73 /]#
//解压,下载软件包
[root@4fc4c145ed73 /]# cd /usr/src/
[root@4fc4c145ed73 src]# ls
debug kernels nginx-1.20.2.tar.gz
[root@4fc4c145ed73 src]# tar xf nginx-1.20.2.tar.gz
[root@4fc4c145ed73 src]# cd nginx-1.20.2
[root@4fc4c145ed73 nginx-1.20.2]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make
//编译
[root@4fc4c145ed73 nginx-1.20.2]# useradd -r -M -s /sbin/nologin nginx
[root@4fc4c145ed73 nginx-1.20.2]# mkdir -p /var/log/nginx
[root@4fc4c145ed73 nginx-1.20.2]# chown -R nginx.nginx /var/log/nginx/
[root@4fc4c145ed73 nginx-1.20.2]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-debug \
> --with-http_ssl_module \
> --with-http_realip_module \
> --with-http_image_filter_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_stub_status_module \
> --http-log-path=/var/log/nginx/access.log \
> --error-log-path=/var/log/nginx/error.log
[root@4fc4c145ed73 nginx-1.20.2]# make && make install
[root@4fc4c145ed73 nginx-1.20.2]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@4fc4c145ed73 nginx-1.20.2]# source /etc/profile.d/nginx.sh
[root@4fc4c145ed73 nginx-1.20.2]# nginx
[root@4fc4c145ed73 nginx-1.20.2]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
//[root@4fc4c145ed73 /]# vi start.sh
[root@4fc4c145ed73 /]# cat start.sh
#! /bin/sh
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/bin/bash
[root@4fc4c145ed73 /]# chmod +x start.sh
[root@4fc4c145ed73 /]# cd
[root@4fc4c145ed73 ~]# cd /usr/local/nginx/conf/
[root@4fc4c145ed73 conf]# vim nginx.conf
bash: vim: command not found
[root@4fc4c145ed73 conf]# vi nginx.conf
mysql
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xxkk/nginx v1.0 a2f3b6bfb27d 42 minutes ago 549MB
busybox latest d23834f29b38 3 days ago 1.24MB
httpd latest ad17c88403e2 2 weeks ago 143MB
nginx latest ea335eea17ab 2 weeks ago 141MB
centos latest 5d0da3dc9764 2 months ago 231MB
[root@localhost ~]# docker run -tid --name mysql centos
0fa25df5a003e963f556e8528fb823111121cb76b8e44add47e607d85d83ccf7
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0fa25df5a003 centos "/bin/bash" 5 seconds ago Up 4 seconds mysql
[root@localhost ~]# docker exec -it 0fa25df5a003 /bin/bash
[root@0fa25df5a003 /]#
[root@0fa25df5a003 /]#
[root@0fa25df5a003 /]#
[root@0fa25df5a003 /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@0fa25df5a003 /]# cd /usr/src/
[root@0fa25df5a003 src]# ls
debug kernels mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
[root@0fa25df5a003 src]# tar xf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@0fa25df5a003 src]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs numactl libaio*
[root@0fa25df5a003 src]# cd /usr/local/
[root@0fa25df5a003 local]# ls
bin etc games include lib lib64 libexec mysql-5.7.35-linux-glibc2.12-x86_64 sbin share src
[root@0fa25df5a003 local]# mv mysql-5.7.35-linux-glibc2.12-x86_64 mysql
[root@0fa25df5a003 local]# ls
bin etc games include lib lib64 libexec mysql sbin share src
[root@0fa25df5a003 local]# useradd -r -M -s /sbin/nologin mysql
[root@0fa25df5a003 local]# chown -R mysql.mysql /usr/local/mysql
[root@0fa25df5a003 local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@0fa25df5a003 local]# . /etc/profile.d/mysql.sh
[root@0fa25df5a003 local]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[root@0fa25df5a003 local]# mkdir -p /opt/data
[root@0fa25df5a003 local]# chown -R mysql.mysql /opt/data/
[root@0fa25df5a003 local]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/
2021-12-03T13:11:32.542109Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-12-03T13:11:32.799010Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-12-03T13:11:32.849877Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-12-03T13:11:32.904617Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 893e6255-543a-11ec-b185-0242ac110002.
2021-12-03T13:11:32.905732Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-12-03T13:11:33.893813Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-12-03T13:11:33.893843Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-12-03T13:11:33.894347Z 0 [Warning] CA certificate ca.pem is self signed.
2021-12-03T13:11:34.341136Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@0fa25df5a003 local]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
'/usr/local/include/mysql' -> '/usr/local/mysql/include/'
[root@0fa25df5a003 local]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@0fa25df5a003 local]# ldconfig
[root@0fa25df5a003 local]# vi /etc/my.cnf
[root@0fa25df5a003 local]# catt /etc/my.cnf
bash: catt: command not found
[root@0fa25df5a003 local]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
[root@0fa25df5a003 local]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@0fa25df5a003 local]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /usr/local/mysql/support-files/mysql.server
[root@0fa25df5a003 local]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /usr/local/mysql/support-files/mysql.server
[root@0fa25df5a003 local]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/opt/data/0fa25df5a003.err'.
SUCCESS!
[root@0fa25df5a003 local]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 80 *:3306 *:*
[root@0fa25df5a003 local]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password('1');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@0fa25df5a003 local]# cd /
[root@0fa25df5a003 /]# vi start.sh
[root@0fa25df5a003 /]# chmod +x start.sh
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0fa25df5a003 centos "/bin/bash" 21 minutes ago Up 21 minutes mysql
[root@localhost ~]# docker commit -p -c 'CMD ["/bin/bash","/start.sh"]' 0fa25df5a003 xxkk/mysql:v1.0
sha256:569d00a1eded6dce379744e8ee1a7b3c21c8e28d41d4e47e10e2f1df752de1a7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xxkk/mysql v1.0 569d00a1eded 32 seconds ago 3.81GB
xxkk/nginx v1.0 a2f3b6bfb27d About an hour ago 549MB
busybox latest d23834f29b38 3 days ago 1.24MB
httpd latest ad17c88403e2 2 weeks ago 143MB
nginx latest ea335eea17ab 2 weeks ago 141MB
centos latest 5d0da3dc9764 2 months ago 231MB
nginx[root@localhost ~]# docker run -tid --name nginx centos4fc4c145ed73916c7893e39837a5a04b3fbbc18dba0cf09f85c9e4f4efb588c1[root@localhost ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES4fc