如何重新连接到docker容器 [英] how to reconnect to a docker container

查看:381
本文介绍了如何重新连接到docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个docker容器运行ubuntu和一个简单的节点快速站点。



我连接到容器如下

  docker run -i -t -p 8080:3000 node-express 

容器中的节点应用程序正在运行pm2,所以一旦我退出了容器,它就会继续。

  CONTAINER ID IMAGE 
f32de2737e80 node-express:最新

现在假设我想要对我的应用程序的更新。



我假设我需要连接到容器,停止节点应用程序,并进行更新,例如 git pull 然后重新启动它。



我的第一个问题是如何重新连接到此容器?



另一个问题是,在生产中更新正在运行的容器是否正常?

解决方案

您可以考虑 docker exec 在运行容器中打开一个bash。



另请参见码头附件和码头处理程序之间的差异执行

  docker exec -it f32de2737e80 bash 

但是评论说,更新应用程序应该通过修改Dockerfile和重建图像来完成。


I have a docker container running ubuntu and a simple node express site.

I connected to the container as follows

docker run -i -t -p 8080:3000 node-express

The node app in the container is running with pm2, so it continues once I exit out of the container.

CONTAINER ID        IMAGE
f32de2737e80        node-express:latest

Now assume I want to make an update to my app.

I assume I need to connect to the container, stop the node app, and make an update, e.g. git pull then restart it.

My first question is how do I reconnect to this container?

Another question I have, Is this a normal approach for updating a running container in production?

解决方案

You can consider docker exec to open a bash in your running container.

See also "difference between docker attach and docker exec"

docker exec -it f32de2737e80 bash

But as commented, updated the app should be done by modifying a Dockerfile and rebuilding an image.

这篇关于如何重新连接到docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆