DEV Community

ankit-brijwasi
ankit-brijwasi

Posted on

Running Docker Containers created using docker-compose

So, Recently I was experimenting with docker, and it occured to me that, how can I access the docker containers that are created using, docker-compose.

when I used, the docker ps -a command, I can see all my containers that are created by docker-compose.

docker ps -a result

But when I tried to run a container, It didn't run.

docker run result

The answer to this was quite simple.

1. To start a container use-

$ docker container start container_name
Enter fullscreen mode Exit fullscreen mode

Note: The configuration specified for the container in the docker-compose file will be applied to the container by default so, you don't have to do them manually.

docker ps result

2. To stop a container use-

$ docker container stop container_name
Enter fullscreen mode Exit fullscreen mode

3. To open up bash in the container use-

$ docker container exec -it container_name bash
bash-5.1# 
Enter fullscreen mode Exit fullscreen mode

And that's it!
Thanks for reading!
Have a marvelous day!😇

Top comments (0)