Dockerfile 文件内容
FROM centos
COPY nginx.repo /etc/yum.repos.d
RUN yum localinstall -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm \
&& curl -sL https://rpm.nodesource.com/setup_10.x | bash - \
&& yum install -y mysql-community-server \
&& yum install -y initscripts \
&& yum install -y nodejs \
&& yum install -y nginx \
&& yum clean all
CMD ["/usr/sbin/init"]
nginx.repo 文件内容
# nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
由 Dockerfile 文件构建镜像
docker build -t centos76-mysql8-jdk8-node-nginx:latest .
保存镜像到文件
docker save > centos76-mysql8-jdk8-node-nginx.tar centos76-mysql8-jdk8-node-nginx:latest
启动容器 挂载jdk8主机目录
docker run --privileged=true --name "centos76-mysql8-jdk8-node-nginx" --mount type=bind,source=/Users/moonnow/wode/cs/docker/2,target=/opt/jdk8 -d -i -t centos76-mysql8-jdk8-node-nginx /usr/sbin/init
进入容器
docker exec -i -t centos76-mysql8-jdk8-node-nginx /bin/bash
由映射目录直接解压jdk8 避免拷贝压缩包到容器 以保持镜像最小
tar -zxvf /opt/jdk8/jdk-8u191-linux-x64.tar.gz -C /
编辑环境变量文件
vi /etc/bashrc
写入如下内容
export JAVA_HOME=/jdk1.8.0_191
export PATH=$JAVA_HOME/bin:$PATH
export PATH
启动 mysql 服务
service mysqld start
修改密码 开启远程连接
yourpassword 改为自己的密码 密码强度要符合要求 须同时包含 大小写字母 数字 符号
mysqlpass=`grep 'temporary password' /var/log/mysqld.log`
mysql -uroot -p${mysqlpass##* } --connect-expired-password -e"ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';use mysql;UPDATE user SET HOST = '%' WHERE USER = 'root';flush privileges;"
启动 nginx
nginx
把自己修改后的容器 提交为镜像
docker commit -a "moonnow" -m "password:yourpassword" centos76-mysql8-jdk8-node-nginx moonnow/centos76-mysql8-jdk8-node-nginx:latest
保存镜像到文件
docker save > moonnowcentos76-mysql8-jdk8-node-nginx.tar moonnow/centos76-mysql8-jdk8-node-nginx:latest
启动容器 添加端口映射 自己修改后的镜像 不需要启动 mysql 服务 启动容器后数据库就可以用了
docker run --privileged=true --name "moonnowcentos76-mysql8-jdk8-node-nginx" -d -i -t -p 9906:3306 -p 9980:80 moonnow/centos76-mysql8-jdk8-node-nginx /usr/sbin/init
进入容器
docker exec -i -t moonnowcentos76-mysql8-jdk8-node-nginx /bin/bash