How to docker attach to a container - Google Cloud Platform / Kubernetes

3/19/2015

I have a containerized app running on a VM. It consists of two docker containers. The first contains the WebSphere Liberty server and the web app. The second contains PostgreSQL and the app's DB.

On my local VM, I just use docker run to start the two containers and then I use docker attach to attach to the web server container so I can edit the server.xml file to specify the public host IP for the DB and then start the web server in the container. The app runs fine.

Now I'm trying to deploy the app on Google Cloud Platform.

  1. I set up my gcloud configuration (project, compute/zone).
  2. I created a cluster.
  3. I created a JSON pod config file which specifies both containers.
  4. I created the pod.
  5. I opened the firewall for the port specified in the pod config file.

At this point:

  1. I look at the pod (gcloud preview container kubectl get pods), it shows both containers are running.
  2. I SSH to the cluster (gcloud compute ssh xxx-mycluster-node-1) and issue sudo docker ps and it shows the database container running, but not the web server container. With sudo docker ps -l I can see the web server container that is not running, but it keeps trying to start and exiting every 10 seconds or so.

So now I need to update the server.xml and start the Liberty server, but I have no idea how to do that in this realm. Can I attach to the web server container like I do in my local VM? Any help would be greatly appreciated. Thanks.

-- Alex Feinberg
google-cloud-platform
google-kubernetes-engine
kubernetes

2 Answers

4/2/2015

On the machine itself, you can see crash looping containers via:

docker ps -a

and then

docker logs

you can also use kubectl get pods -oyaml to get details like restart count that will validate that the container is crash-looping.

-- brendan
Source: StackOverflow

9/2/2015

Yes, you can attach to a container in a pod. Using Kubernetes 1.0 issue the following command:

Do:

  • kubectl get po to get the POD name
  • kubectl describe po POD-NAME to find container name

Then:

kubectl exec -it POD-NAME -c CONTAINER-NAME bash Assuming you have bash

Its similar to docker exec -it CONTAINER-NAME WHAT_EVER_LOCAL_COMMAND

-- michaelbn
Source: StackOverflow