上一篇我们遇到了一个小障碍,web页面的乱码,准备把网页里的内容替换成英文。

首先我们进入容器,把html里的内容替换掉

[[email protected] docker_nginx]# docker exec-it web /bin/bash

[email protected]:/# echo 'happy new year ,dog year wang wang' > /usr/share/nginx/html/index.html

我原以为替换掉之后重启nginx服务就可以,尴尬地发现,重启服务之后,容器退出了

在docker中构建nginx服务(排错)

之前给大家提到过,容器具有写时复制的特性,也就是说,刚刚我们所做的修改全部在读写层,文件底层内容并没有改变。也就是说,如果我们把这个容器重启,那么web界面里的内容依然是中文的,依然乱码;

其实,我们再创建镜像时又两种方式:一种就是像上一篇说的,利用dockerfile去从无到有的去创建一个镜像,另一种就是对已有的容器进行修改,再把这个容器提交为镜像,这种动作称为commit。

首先我们先把原来的容器删掉,重新运行一个

[[email protected] docker_nginx]# docker rm -f 8b9e123d35819a059da47d10d19e4b0c27168a1b

8b9e123d35819a059da47d10d19e4b0c27168a1b7d9ef54324504839fd0f817e

[[email protected] docker_nginx]# docker run -d -p 80:80 --name web 8ad05e091619 nginx

afa0c42bc4c7130937528fbb5baa3771063e5089b00ab3104eb911fc22424927

在docker中构建nginx服务(排错)

进入容器,把html文件内容更改掉

[[email protected]_nginx]# docker exec -itafa0c42bc4c7130937528fbb5baa3771063e5089b00ab3104eb911fc22424927  /bin/bash

[email protected]:/#echo 'happy new year , dog year wang wang' >/usr/share/nginx/html/index.html

在docker中构建nginx服务(排错)

将容器提交

[[email protected] docker_nginx]# dockercommit afa0c42bc4c7 happynewyear

删除原有的容器(如果不删除,那么新容器映射时不要映射宿主机的80端口)

docker rm -f afa0c42bc4c7

用新提交的镜像创建容器

docker run -d -p 80:80 --name happywebhappynewyear nginx -g "daemon off;"

在docker中构建nginx服务(排错)

大功告成,祝大家新年快乐,狗年大吉!

在docker中构建nginx服务(排错)

 

相关文章:

  • 2021-04-19
  • 2021-12-24
  • 2022-12-23
  • 2021-10-25
  • 2021-11-27
  • 2022-12-23
  • 2021-09-27
  • 2021-12-27
猜你喜欢
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-09
相关资源
相似解决方案