Docker image_ssh_systemctl_nginx_tomcat_mysql

docker image

Download centos: 7 mirror

docker images
docker pull centos:7
docker images
Insert picture description here

1. SSH mirror

mkdir sshd
cd sshd

vim Dockerfile
FROM centos:7
MAINTAINER li
RUN yum -y update
RUN yum -y install openssh* net-tools lsof telnet passwd
RUN echo '123456' | passwd --stdin root
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN sed -i '/^session\s\+required\s\+pam_loginuid.so/s/^/#/' /etc/pam.d/sshd
RUN mkdir -p /root/.ssh && chown root.root /root && chmod 700 /root/.ssh
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]

Insert picture description here

1. Generate a mirror

docker build -t sshd:test .
Insert picture description here
2. Start the container
docker run -d -P sshd:new


ssh localhost -p 49154
Insert picture description here

Two. systemctl mirror

  • --Privateged enables the root in the container to have real root privileges, and does not perform de-privation processing. Otherwise, the user in the container is just an external user
mkdir systemctl
cd systemctl

vim Dockerfile

FROM sshd:new

ENV container docker


RUN (cd /lib/systemd/system/sysinit.target.wants/;for i in *;do [ $i ==\
systemd-tmpfiles-setup.service ] || rm -f $i;done);\
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*;\
rm -f /lib/systemd/system/sockets.target.wants/*udev*;\
rm -f /lib/systemd/system/sockets.target.wants/*initctl*;\
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;


VOLUME ["/sys/fs/cgroup"]

CMD ["/usr/sbin/init"]
Insert picture description here

1. Generate a mirror

docker build -t systemctl:systemctl .
Insert picture description here

2. Start the container

docker run --privateged -it -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd:systemctl /sbin/init & 
Insert picture description here
Insert picture description here
Insert picture description here

Three.nginx mirror

mkdir nginx
cd nginx/
Insert picture description here
FROM centos:7

MAINTAINER li

RUN yum -y update
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make
RUN useradd -M -s /sbin/nologin nginx


ADD nginx-1.12.0.tar.gz /usr/local/src
WORKDIR /usr/local/src

WORKDIR nginx-1.12.0
RUN ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module && make && make install
ENV PATH /usr/local/nginx/sbin:$PATH

EXPOSE 80
EXPOSE 443
RUN echo "daemon off;">>/usr/local/nginx/conf/nginx.conf
ADD run.sh /run.sh
RUN chmod 755 /run.sh
CMD ["/run.sh"]
Insert picture description here
vim run.sh

#!/bin/bash
/usr/local/nginx/sbin/nginx
Insert picture description here

1. Generate a mirror

docker build -t nginx:nginxweb .
Insert picture description here
2. Start the container
Insert picture description here
Insert picture description here

Four. Tomcat mirror

Insert picture description here
vim Dockerfile


FROM centos:7

MAINTAINER li

COPY jdk-8u201-linux-x64.rpm /
RUN rpm -ivh jdk-8u201-linux-x64.rpm


ENV JAVA_HOME /usr/java/jdk1.8.0_201-amd64
ENV CLASSPATH /usr/java/jdk1.8.0_201-amd64/lib/tools.jar:/usr/java/jdk1.8.0_201-amd64/lib/dt.jar
ENV PATH /usr/java/jdk1.8.0_201-amd64/bin:$PATH


ADD apache-tomcat-9.0.16.tar.gz /usr/local/
WORKDIR /usr/local/
RUN mv apache-tomcat-9.0.16 /usr/local/tomcat


ENTRYPOINT ["/usr/local/tomcat/bin/catalina.sh","run"]
Insert picture description here

1. Generate a mirror

docker build -t tomcat:centos7 .
Insert picture description here
2. Start the container
docker run -d --name tomcat1 -p 1111:8080 tomcat:centos7
Insert picture description here

3. Verification

Insert picture description here

5.mysql mirror

Insert picture description here
1.mysql configuration file
vim my.cnf
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
Insert picture description here
2.Dockerfile file
vim Dockerfile


FROM centos:7

MAINTAINER li

RUN yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake make

RUN useradd -M -s /sbin/nologin  mysql

ADD mysql-boost-5.7.20.tar.gz /opt
WORKDIR /opt/mysql-5.7.20/
RUN cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1 && make -j4 && make install

RUN rm -f /etc/my.cnf
COPY my.cnf /etc

RUN chown -R mysql:mysql /usr/local/mysql/
RUN chown mysql:mysql /etc/my.cnf


ENV PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib


WORKDIR /usr/local/mysql/
RUN bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data


RUN cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/


EXPOSE 3306

RUN echo -e "#!/bin/sh \nsystemctl enable mysqld" >/run.sh
RUN chmod 755 /run.sh
RUN sh /run.sh
CMD ["init"]
Insert picture description here


Insert picture description here
3. Create a mirror
docker build -t mysql:centos7 .
Insert picture description here
4. Innovate the container and run
docker images
docker run --name=mysql_server -d -P --privileged mysql:centos7
docker ps -a
Insert picture description here
5. Enter the container and authorize
docker exec -it fe467047ad6b /bin/bash
mysql -uroot -p
回车,此时没有密码

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'abc123';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'abc123';
flush privileges;

另开终端,用于测试
yum -y install mariadb*
docker ps -a
mysql -h 192.168.163.100 -u root -P 49157 -pabc123
Insert picture description here
6. Test
show databases;
create database rongqi;
create database VM;
Insert picture description here


Insert picture description here