Member-only story
How To Interact with your Docker Containers using docker container exec -it commands?

A few quick and simple tips on how to access your Docker Containers.
Make sure to have docker installed on your OS. For further instructions on installing Docker visit the link here.
First let’s begin with the following command. We plan to list any current running containers on the OS. This will show all the containers available to execute commands in.
If a Docker Container has a Failed State or a Stopped State, you will not be able to execute a command within it. Make sure your containers are in a running state before running docker container exec -it.
Getting Started with docker container exec -it
Use the following command to list you containers.
docker ps
You’ll now see a table with a few containers running, this will vary depending on your setup.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Next you will need to find the container ID of your project you would like to Exec into using Docker Exec. The format of the container ID will be a hashed ID.
How to Interact With Your Docker Container using the docker container exec -it Command?
We will walk you through, how to access your container. The first part of the command, you will need to use is.
docker exec -it
As you may experience, the command will not work unless you add the container ID at the end and a few other flags. Let’s add those in to the docker container exec -it command.
Use the following code below as an Example.
Here you can see we have added the the -it flag and container ID.
docker exec -it xT9o187vhyE1
However, you may still receive an error message.
You are now missing the command you wish to execute.
Now lets execute your command, named /bin/sh or /bin/bash
docker exec -it xT9o187vhyE1 /bin/bash