How do I add a package as a fourth Docker container?

0
0
Asked By MellowCedar47 On

I have an Ubuntu 24 server running on a DigitalOcean Droplet, and three containers are currently listed by Docker. I want to add another package so it runs in its own container, giving me four containers in total. I have a shell script that installs the package and tried copying it into a container named "somepkg," making it executable, running it, and then deleting it. However, Docker returned "No such container: somepkg." I assumed this process would create the container, but it appears I am missing an initial step. What is the proper way to do this?

3 Answers

Answered By BrightPanda8 On

`docker cp` and `docker exec` only work with a container that already exists; they do not create one. If this package should run as its own service, build an image for it with a Dockerfile, then create and start a container with `docker run` or, preferably, define it in a Docker Compose file. You can then start it alongside the existing services and Docker will show the additional container.

Answered By SilverMango19 On

First verify whether `somepkg` is actually the name of an existing container. Run `docker container ls --all`; an image name and a container name are different things. Regardless, you still need to build or obtain a container image and then start a container from it before `docker cp` or `docker exec` can be used.

MellowCedar47 -

That makes sense. I was treating the package name as if it were already a container. I’ll look into creating a Dockerfile and starting the service from the resulting image.

Answered By QuietOrbit_62 On

If the package belongs inside one of your existing services, extend that service's image instead of copying an installation script into a running container. Add the required installation commands to a Dockerfile, rebuild the image, and recreate the container. Changes made manually inside a running container are generally lost when that container is removed or recreated.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.