docker exec
Runs an extra command inside a container that is already running.
In more detail
The new process joins the container namespaces and filesystem but has its own lifetime and exit code; it is not the main process. docker exec -it name sh opens an interactive shell for diagnosis. It cannot enter a stopped container because there are no running namespaces to join.
Examples
docker exec -it command-demo shdocker exec m01l02-broker rpk cluster infoecho login | docker exec -i broker rpk topic produce eventsRelated terms
- docker logs — Shows what a container main process wrote to standard output and standard error.
- interactive terminal — The -it flags that connect your keyboard to a container and give it a terminal, so you can use a shell inside it.
- process — A program that is currently running, with its own memory and a numeric identifier.
- namespace (Linux) — A Linux kernel feature that controls what a process can see, such as which other processes, network or host name.
- rpk — The command-line tool that ships with Redpanda for starting brokers and managing topics, consumer groups and schemas.
- psql — PostgreSQL's interactive command-line client for running SQL statements.
Taught in
- Run, Stop, Restart And Remove A Container — Docker Architecture & Production Containers
- Commands, Logs, Exec And Exit Codes — Docker Architecture & Production Containers
- CMD, ENTRYPOINT, USER And Process Signals — Docker Architecture & Production Containers
- Minimal Bases, Non Root Users And Smaller Images — Docker Architecture & Production Containers
- Bridge Networks, DNS And Container Communication — Docker Architecture & Production Containers
- Port Publishing, Localhost And Network Troubleshooting — Docker Architecture & Production Containers
- Environment, Secret Files And Runtime Restrictions — Docker Architecture & Production Containers
- Define The Service And Database With Compose — Docker Architecture & Production Containers
- Health Checks, Dependencies And Reliable Startup — Docker Architecture & Production Containers
- Development Overrides, Hot Reloading And Debuggers — Docker Architecture & Production Containers
- Integration Tests, Test Data And Compose Cleanup — Docker Architecture & Production Containers
- Build, Test And Promote The Same Image In CI — Docker Architecture & Production Containers
- Harden And Deliver The Complete Service Stack — Docker Architecture & Production Containers
- Shipping in Scratch and Distroless Images — Concurrent Systems Programming with Go
- Why A Log And Not A Queue — Apache Kafka & Event Streaming
- Dual Writes And Why They Lose Data — Apache Kafka & Event Streaming
- One File, Five Services: Stacks From Compose Files — Docker Certified Associate (DCA) Exam Prep
- Stuck In Pending: Troubleshooting Services And Reading docker inspect — Docker Certified Associate (DCA) Exam Prep
- Twelve Lines, Ten Warnings: Dockerfile Instructions And hadolint — Docker Certified Associate (DCA) Exam Prep
- Our Own Registry: Deploy, Push, Pull, Search And Delete — Docker Certified Associate (DCA) Exam Prep
- Images Sprint: Eight Questions On Builds, Tags And Registries — Docker Certified Associate (DCA) Exam Prep
- Who Let Femi In? UCP Roles, Grants, LDAP And Client Bundles — Docker Certified Associate (DCA) Exam Prep
- Security Sprint: Eight Questions On Defaults, Trust And Access — Docker Certified Associate (DCA) Exam Prep
- Friday, Nine In The Morning: The Mock Exam And Its Report — Docker Certified Associate (DCA) Exam Prep