Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "Docker run" creates new container every time?

I ran docker run ubuntu couple of times. When I list the containers using docker ps -a, it list down many containers with different ID. Why does docker creates new container every time instead of the one which is not in use? Doesn't that container occupies some space? Could someone please clarify ?

like image 343
itspr Avatar asked Jan 27 '19 23:01

itspr


People also ask

Why does my container automatically restart?

If you are using docker-compose this might be useful to know. restart no is the default restart policy, and it does not restart a container under any circumstance. When always is specified, the container always restarts. The on-failure policy restarts a container if the exit code indicates an on-failure error.

How do I stop docker container from starting automatically?

Deselect 'Start Docker when you log in' on the General tab. Close the Preferences window. Quit Docker (Cmd-Q or use the menu).

How do I stop a restarting container?

If you want to stop a docker container here's the command to do it. The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL. This will stop a running container. This would restart the container.

How do you prevent processes from gaining new privileges in the container?

The no-new-privileges security option prevents the application processes inside the container from gaining new privileges during execution. So even if: there is a program with the setuid/setgid bit set in the image, such as sudo. a process in the container has (file) permissions to execute the program.


1 Answers

docker container run is a shorthand for docker container create and docker container start. So, by definition, it creates a new container every time.

$ docker container run --help

Usage:  docker container run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

You can start stopped containers (perhaps created by docker container run) with docker container start ….

like image 57
King Chung Huang Avatar answered Oct 06 '22 23:10

King Chung Huang