Can we have a single container with multiple image like nginx + Redis + alpine?

Can we have a single container with multiple image like nginx + Redis + alpine ?

1 Like

You can have multiple processes inside a container but it wouldn’t really be a best practice.

Having NGINX and Redis in separate containers but inside the same pod would be better. But then NGINX and Redis are tied together, so you could not form example scale NGINX.

The typically scenarios would be NGINX and Redis in separate pods.

Keep in mind I have know idea what you app architecture is, I’m just assuming a typical web server / database arch where you might want to scale the web server later.

Kind regards,
Stephen

1 Like

Thanks Stephen for your answer,

I got your point, I just want to know if we have to create Pod with single container which has to use the image redis + nginx + memcached. Then below are questions:

  1. Is this possible?
  2. if yes, how to create it,. Any way interactive or yaml based ? please share the yaml file if possible

Running containers is Kubernetes responsibility.
Building containers, which is what you are describing, is Dockers (Or other runtimes) responsibility.

You need to look at Docker documentation in order to build a container with multiple processes.

This page seems to give a good overview:

Again though, I’ll advise against it.
Unless you have specific technical need, it is actually more complicated to build the container with multiple processes than it would be to run a pod with multiple single process containers. You need to manage an entry point script which will then fork and manage all the required processes.

Kind regards,
Stephen

1 Like

Thanks Stephen

hi @eyadaje,

Were you able to figure this out? I am also looking for a solution for this.

I’m also looking for the solution…anyone please.

The “solution” to what problem?

If you want to build a single image with multiple apps in it (why?) you can do that through Docker or any other image creation tooling.

If you want to run a pod with multiple containers in it, there’s a TON of docs and examples on how to do that.

Please help us understand what you are trying to do, what you have already tried, and what didn’t work.

1 Like

you could run docker inside docker, using docker:dind

ssh to worker node,

docker run --privileged -d --name dind-test docker:dind
docker exec -it dind-test /bin/sh
docker pull nginx
docker pull redis
docker pull memcached 
docker run --name nginx -d nginx
docker run --name redis -d redis
docker run --name memcache -d memcached

exit from the container

exit

from the worker node

docker ps -a 
docker tag <container-id> docker:multi-cont

now exit from node

exit

Deploy the pod using this image,

kubectl run multi-cont --image=docker:multi-cont --restart=Never --dry-run -o yaml > ng.yaml

and update the imagePullPolicy to IfNotPresent

kubectl apply -f ng.yaml

we can’t tag container before commit it.
After committing it and then creating image out of it image failed to start the container.
Anyone tried this solution and it worked.

Did you find the solution?

ya, I missed that one.

correction
from worker node,

docker ps -a 
docker commit
docker tag <container-id> docker:multi-cont

what error you are seeing? can you describe pod? did you update pullPolicy?

I am not sure the pod is in carshloopback.
Also I created the docker container out of image and tried to the get the container running in it it give me following error:
docker exec -it ca6c0d2e2f52 sh
/ # docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

It seems like the docker commit and docker tag commands are incorrect? Does anyone able to get the correct command

controlplane $ docker tag ae31e16499be docker:multi-cont
Error response from daemon: No such image: ae31e16499be:latest

I think the command should be like this
docker commit “container-id”
docker tag “image-id” docker:multi-cont

Also after creating the image, i tried giving reference of the local image in yaml file with above mentioned imagePullPolicy, but getting error to fetch the image