how to reconnect to a docker container

2019-05-16 16:23发布

问题:

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?

回答1:

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.