Lesson 11 / 28

Naming Containers

Name containers with --name so logs, exec and stop commands are easy to run.

--name

Without --name, Docker assigns a random name like happy_curie. Naming it yourself makes later commands readable.

docker run -d --name web -p 8080:80 nginx
docker logs web
docker stop web

Names must be unique

You can't reuse a name while another container (even a stopped one) still holds it — remove the old one first with docker rm.