获取镜像
docker pull nginx:1.18
docker pull php:5.6-fpm
php安装扩展
docker run -d --name php-build
docker exec -it container-ID /bin/bash
apt install libxml2*
docker-php-ext-install bcmath calendar dba exif gd hash iconv mbstring mcrypt mysql mysqli odbc opcache pcntl pdo pdo_mysql phar session sockets spl standard sybase_ct sysvmsg sysvsem sysvshm tokenizer xml xsl zip soap
安装好扩展后提交为镜像
docker commit -m="php5.6v2 change php-fpm process" 886936ffca51 srv-php5.6:v2
构建nginx+php环境
mkdir -p /srv/service/jp/nginx/{www,conf}
docker run --name app-php -v /srv/service/jp/nginx/www:/www -d srv-php5.6:v2
docker run --name php-nginx -p 8083:80 -d \
-v /srv/service/jp/nginx/www:/usr/share/nginx/html:ro \
-v /srv/service/jp/nginx/conf:/etc/nginx/conf.d:ro \
--link app-php:php \
nginx:1.18.0
docker重命名镜像
docker tag images_id 仓库名:版本号
docker rmi 旧仓库名:版本号
docker向ECR中推送镜像
#ECR要先建好私有仓库,xms-nginx
[root@ops-node01 www]# docker images //查看本地镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
xms-php 5.6 cf6861db75ff 27 hours ago 970MB
mysql 5.7 697daaecf703 13 days ago 448MB
nginx 1.18 05f64a802c26 2 weeks ago 133MB
xms-nginx 1.18.0 05f64a802c26 2 weeks ago 133MB
gitlab/gitlab-ce 13.6.1-ce.0 9a53eb68aeeb 4 weeks ago 2.07GB
[root@ops-node01 www]# docker tag xms-nginx:1.18.0 263138086182.dkr.ecr.us-west-2.amazonaws.com/xms-nginx:1.18.0 //打上标签
[root@ops-node01 www]# docker push 263138086182.dkr.ecr.us-west-2.amazonaws.com/xms-nginx:1.18.0 //push到ECR
The push refers to repository [263138086182.dkr.ecr.us-west-2.amazonaws.com/xms-nginx]
1e09835f552f: Pushed
c557ef8ec54b: Pushed
9fdf28d5d9e1: Pushed
dcb1b4f410a8: Pushed
87c8a1d8f54f: Pushed
1.18.0: digest: sha256:414305b81359f7d079a9f483fdb45f88167387abda977d0b3e3c3d606fbe1244 size: 1362
[root@ops-node01 www]#
docker启动mysql5.6
#拉取基础镜像
docker pull mysql:5.6
#创建配置文件和db存放目录
mkdir /opt/docker/mysql/db-jp
vim /opt/docker/mysql/my-jp.cnf
[mysqld]
user=mysql
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names=1
event_scheduler=ON
max_connections=1000
#启动数据库
docker run -d --name xms-mysql-jp -v /opt/docker/mysql/db-jp:/var/lib/mysql -v /opt/docker/mysql/my-jp.cnf:/etc/mysql/my.cnf --restart always -p 4000:3306 -e MYSQL_ROOT_PASSWORD=akka7jfj981k123a32nb mysql:5.6