去评论
海欣资源

docker如何修改容器内nginx配置文件

xx5678
2022/05/04 18:51:40
一、使用nohup启动指定jar包并指定端口和日志文件
nohup java -jar ****-app.jar --server.port=8084 >>rzwmsj-app.out &
二、进入docker容器
docker exec -it 9df70f9a0714 bash  #使用容器 ID   
docker exec -it mynginx /bin/sh #使用名字

三、安装vim
1.尝试直接安装vim,报错
apt-get install vim
Reading package lists... Done
Building dependency tree      
Reading state information... Done
E: Unable to locate package vim
2.更换网易源,有一个下载不下来
mv /etc/apt/sources.list /etc/apt/sources.list.bak
    echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >> /etc/apt/sources.list
    echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
    echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list
    echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
    #更新安装源
apt-get update
Err:4 http://mirrors.163.com/debian jessie-proposed-updates Release
  404  Not Found [IP: 101.71.33.11 80]
3.更换阿里源
echo "">sources.list
  echo "deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib">>sources.list
  echo "deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib">>sources.list
  echo "deb http://mirrors.aliyun.com/debian-security stretch/updates main">>sources.list
  echo "deb-src http://mirrors.aliyun.com/debian-security stretch/updates main">>sources.list
  echo "deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib">>sources.list
  echo "deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib">>sources.list
  echo "deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib">>sources.list
  echo "deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib">>sources.list
  echo "deb https://deb.debian.org/debian buster main contrib non-free">>sources.list
  echo "deb-src https://deb.debian.org/debian buster main contrib non-free">>sources.list
  echo "deb https://deb.debian.org/debian buster-updates main contrib non-free">>sources.list
  echo "deb-src https://deb.debian.org/debian buster-updates main contrib non-free">>sources.list
  echo "deb https://deb.debian.org/debian buster-backports main contrib non-free">>sources.list
  echo "deb-src https://deb.debian.org/debian buster-backports main contrib non-free">>sources.list
  apt-get update
成功安装yum和vim
apt-get install yum
apt-get install vim

四、修改nginx文件
按照日常修改即可
server{
  listen 443 ssl;
  # charset utf-8;
  server_name ***.*****.com;

  ssl_certificate /etc/nginx/conf.d/_.***.com.pem;
  ssl_certificate_key /etc/nginx/conf.d/_.***.com.key;
  ssl_session_timeout 5m;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256HE-RSA-AES256-GCM-SHA384HE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHAHE-RSA-AES256-SHA256HE-RSA-AES128-SHA256HE-RSA-AES256-SHAHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHAES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
# ssl_ciphers 'AES128+EECDH:AES128+EDH';
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
  ssl_prefer_server_ciphers on;
  ssl_session_cache shared:SSL:10m;

  location / {
      proxy_pass http://***.***.***.***:8081;
      proxy_redirect default;
}
  location /*****{
      proxy_pass http://***.***.***.***:8084;
      proxy_redirect default;
}
}

五、重启nginx
docker stop mynginx
docker start mynginx
最后发现,直接用cp复制一个进去更简单
# 从宿主机拷贝到docker容器
    docker cp /etc/nginx/conf.d/***.conf 96f7f14e99ab:/nginx/conf.d/***.conf
然后重启nginx容器
docker stop mynginx
docker start mynginx