![]() ![]() The -i option stands for interactive, and -t tells Docker to allocate a pseudo TTY device. To execute a command inside the container run the following command: docker container exec -it my_mysql ls /var This will create a container named “my_mysql”. We’ll use the official MySQL image: docker container run -name my_mysql -d mysql ![]() To see how the exec command works and how it can be used to enter the container shell, first, start a new container. Get a Shell to a Container #Īllows you to run commands inside a running container. If the running processes you are attaching to accepts input, you can send instructions to it. To detach from the container without stopping it, use the CTRL-p CTRL-q key combination. To get access to the container logs you should prefer using the docker logs command. When you run the attach command your terminal attaches to the nginx process.Īnd you can watch the output of the nginx process in real time. The default command of the nginx image which is executed when you run the container is set to CMD. To make sure the “my_nginx” container is running: docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESĨe1c4974a8d8 nginx "nginx -g 'daemon of…" 3 minutes ago Up 2 seconds 0.0.0.0:8080->80/tcp my_nginxĪttach to the container using the container’s ID or name: docker container attach my_nginx The -p 8080:80 option tells Docker to map port 80 in the container to port 8080 on the host machine. docker container run -name my_nginx -d -p 8080:80 nginx To better understand how the attach command works let’s runĪ new detached Nginx container using the official Nginx image. This is useful when you want to see what is written in the standard output in real-time, or to control the process interactively. The command that is executed when starting a container is specified using the ENTRYPOINT and/or RUN instruction.Īllows you to attach your terminal to the running container. Attach to a Container #Īlthough it is possible to run multiple processes in a container, most docker containers are running only a single process. In this tutorial, we will explain how to attach to the container’s main running process and how to get a shell to a running container. You can also enter the container, install new packages, and build a new Docker image If the Docker container doesn’t work as expected, you can attach to the container or get a shell to the container and run commands such as ps Connecting to a running Docker container is helpful when you want to see what is happening inside the container.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |