Monday, January 20, 2025

How to edit files in stopped/not starting docker container

  • ประเด็นคือ คอนฟิก  mysql 9 container /etc/my.cnf  เพิ่มไปให้ใช้ authen native password ได้ 
  • และพยายาม restart container ด้วยคอนฟิกค่าใหม่ 
  • งานเข้าเลยทีนี้ start ขึ้นเป็น stop เอง
  • แก้ปัญหาโดย เอาไฟล์คอนฟิกใน container ที่ stop อยู่ ออกมาแก้ไขแล้ว คัดลอกไปทับ และ start container

Sample

$ docker cp docker_web_1:/etc/apache2/sites-enabled/apache2.conf .

$ docker cp apache.conf docker_web_1:/etc/apache2/sites-enabled/apache2.conf

Solved

  • คัดลอกไฟล์ออกมาก่อนเลย

$ docker cp docker_mysql:/etc/my.cnf .

  • ทำการแก้ไขคอนฟิกไฟล์ให้เหมือนเดิมแล้วสั่งคัดลอกไปทับ

$ docker cp my.cnf docker_mysql:/etc/my.cnf

  • และทำการ start container อีกรอบ

$ docker start docker_mysql

Ref

  • https://stackoverflow.com/questions/32750748/how-to-edit-files-in-stopped-not-starting-docker-container

No comments:

Post a Comment

Popular Posts