更新docker容器中code-server的方法
本人使用code-server的官方镜像进行部署,根据官方文档可知,code-server的用户数据与程序本体是分开的,避免手动安装可能造成的错误,建议直接下载.deb
使用命令行进行安装,例如:
dpkg -i code-server_4.11.0_amd64.deb #根据自身情况判断是否需要加sudo权限,官方镜像使用debian发行版因此用deb类型安装,其他系统会有区别
安装完后重启容器即可,例如
docker restart code-server-container
本人使用以上方案是因为在容器内进行项目的编写,一般容器的用法是容器仅提供单一功能,使用中不改变容器内结构的,因此可以定期更新镜像进行更新。有需要的小伙伴可以进入官方docker hub镜像,学习Updating Info章节内容:
Most of our images are static, versioned, and require an image update and container recreation to update the app inside. With some exceptions (ie. nextcloud, plex), we do not recommend or support updating apps inside the container. Please consult the Application Setup section above to see if it is recommended for the image.
Below are the instructions for updating containers:
Via Docker Compose
Update all images: docker-compose pull
or update a single image: docker-compose pull code-server
Let compose update all containers as necessary: docker-compose up -d
or update a single container: docker-compose up -d code-server
You can also remove the old dangling images: docker image prune
Via Docker Run
Update the image: docker pull lscr.io/linuxserver/code-server:latest
Stop the running container: docker stop code-server
Delete the container: docker rm code-server
Recreate a new container with the same docker run parameters as instructed above (if mapped correctly to a host folder, your /config folder and settings will be preserved)
You can also remove the old dangling images: docker image prune
Via Watchtower auto-updater (only use if you don't remember the original parameters)
Pull the latest image at its tag and replace it with the same env variables in one run:
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--run-once code-server
You can also remove the old dangling images: docker image prune
Note: We do not endorse the use of Watchtower as a solution to automated updates of existing Docker containers. In fact we generally discourage automated updates. However, this is a useful tool for one-time manual updates of containers where you have forgotten the original parameters. In the long term, we highly recommend using Docker Compose.
Image Update Notifications - Diun (Docker Image Update Notifier)
We recommend Diun for update notifications. Other tools that automatically update containers unattended are not recommended or supported.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!