- List Open Ports
lsof -nP +c 15 | grep LISTEN- The above command is useful not only that but also for troubleshooting docker related issues such as spinning up containers and ports already being in use.
- (Security Skill) Command is also useful for in web security to frequently check the ports of your computer and app to see which port are open and close unneeded ports to avoid hole for hackers.
- Check if docker is installed.
$ docker
- Check the version of Docker
$ docker version
- Show number of containers, etc
$ docker info
- Target all containers
$(docker ps -aq)
Basic Commands for working with containers
- List running containers (Even if not running)
$ docker container ls -a- (Running ONLY)
$ docker container lsor$ docker ps
- Get logs (Use name or ID)
$ docker container logs [NAME]
- List processes running in container
$ docker container top [NAME]
- Stop all running containers
- Useful for switch between projects.
$ docker stop $(docker ps -aq)
- Stop container by ID
$ docker container stop [ID]
- Stop individual container
$ docker container rm [ID]
- To remove a running container use force(-f)
$ docker container rm -f [ID]
- Remove all containers
$ docker rm $(docker ps -aq)
- Configure relationships between containers
- Save our docker container run settings in easy to read file
- 2 Parts: YAML File (docker.compose.yml) + CLI tool (docker-compose)
- Check whats running before your start a project
docker && docker ps- Take note on what ports (if any are in use)
- if any are running, stop the them
docker stop $(docker ps -aq)
- Run the project
docker-compose up- (Run in background)
docker-compose up -d
- Stop the Project (Every )
- Best practice is to run this
docker-compose down
- If you run into a problem, READ the console before asking for help.
References: Parts of this MD used from Brad Traversy Tutorials.