Ramon Marques
Ramon Marques

Reputation: 3264

Docker keeping different images and containers

I'm working with dockerized applications and docker-compose.

So sometimes I just run docker-compose up and other times run a particular service docker-compose run service1 /bin/bash

I'm noticing it's increasing a lot of different images and containers using it that way.

For example:

docker images -a
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
<none>                    <none>              7579570fc0f6        3 minutes ago       2.07GB
<none>                    <none>              5c4dff8b6808        8 minutes ago       1.34GB
<none>                    <none>              abf3cb89f2fa        9 minutes ago       1.34GB
<none>                    <none>              7592dcccab3b        9 minutes ago       1.27GB
<none>                    <none>              da2be213241c        9 minutes ago       1.27GB
<none>                    <none>              52bbbc8b88c8        4 weeks ago         1.96GB
<none>                    <none>              77a6403fe043        4 weeks ago         1.96GB
<none>                    <none>              4845935c3110        4 weeks ago         1.23GB
<none>                    <none>              48bca82f00c9        4 weeks ago         1.23GB
<none>                    <none>              63d77ddad079        4 weeks ago         1.94GB
<none>                    <none>              6729473d9848        4 weeks ago         1.94GB
<none>                    <none>              e6ef1c44689f        4 weeks ago         1.23GB

And it's similar with docker container ls -a

It doesn't feel right, am I missing some good practice here? Should I add something to the docker-compose.yml to prevent this?

Update: Have seen the comments about handling dangling images and , but my question here is actually how to prevent this. For example, I know there's a way to run images with a remove tag to destroy it after stop, is it a good practice? I don't see it in the guides so I'm not using, however, the current scenario is making me worried about disk space...

Upvotes: 0

Views: 47

Answers (1)

Navin Gelot
Navin Gelot

Reputation: 1334

Typically docker-compose up. Use up to start or restart all the services defined in a docker-compose.yml. In the default “attached” mode, you see all the logs from all the containers. In “detached” mode (-d), Compose exits after starting the containers, but the containers continue to run in the background.

The docker-compose run command is for running “one-off” or “adhoc” tasks. It requires the service name you want to run and only starts containers for services that the running service depends on. Use run to run tests or perform an administrative task such as removing or adding data to a data volume container. The run command acts like docker run -ti in that it opens an interactive terminal to the container and returns an exit status matching the exit status of the process in the container.

Upvotes: 1

Related Questions