Exec#
When it comes to deploying applications with Docker, you’ll usually just let the container do its thing. For example, the Ghost container we ran in the last chapter started up its own web server (based on the image configuration). We didn’t need to run any manual commands in addition to just starting the container.
That said, it is possible to run commands inside a running container! It’s kinda like the container version of sshing into a remote server and running a command.
List your running containers:
docker psStart up the “getting started” container again:
docker run -d -p 8965:80 docker/getting-startedEnsure that it’s running:
docker psRun an ls command from inside the container using the docker exec command:
docker exec CONTAINER_ID lsCreate a new hacker.log file in the working directory of the container by running touch hacker.log inside the container.
Run the ls command again to make sure that the file was created.
You should get a list of all the files and directories in the working directory (which happens to be the root in this case) of the container!
Live Shell#
Being able to run one-off commands is nice, but it’s often more convenient to start a shell session running within the container itself. Thats where the -i and -t flags come in:
-imakes theexeccommand interactive-tgives us a tty (keyboard) interface- Running
/bin/shgives us a shell session inside the container
docker exec -it CONTAINER_ID /bin/shCompose içinde komut çalıştırmak için docker-compose-basic sayfasındaki docker compose exec bölümüne bak.