How do I add a package as a fourth Docker container?
Asked by
rhythm_section
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?
Answers
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.
Reply to this answer
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.
Reply to this answer
`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.
Reply to this answer
Add your answer
Answers are reviewed before publication.
rhythm_section: 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.