Last active
November 12, 2022 13:39
-
-
Save RakibSiddiquee/8867f0fde290d92151994b734329cdec to your computer and use it in GitHub Desktop.
Docker commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker ps - to show running containers | |
docker ps -a -- to show all containers | |
docker images - to show images | |
Pull an image: | |
-------------- | |
docker pull <image>:<tag> | |
docker pull postgres:14-alpine - pull postgres image | |
Start a container: | |
------------------ | |
docker run --name <container_name> -e <environment_variable> -p <host_ports:container_ports> -d <image>:<tag> | |
docker run --name postgres14 -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -d postgres:14-alpine | |
Start or Stop a container: | |
-------------------------- | |
docker start <container_name_or_id> | |
docker start postgres14 | |
docker stop <container_name_or_id> | |
docker stop postgres14 | |
Run command in container: | |
------------------------- | |
docker exec -it <container_name_or_id> <command> [args] | |
docker exec -it postgres14 psql -U root | |
Exit from console: \q | |
------------------ | |
View container logs: | |
-------------------- | |
docker logs <container_name_or_id> | |
docker logs postgres14 | |
Access container command shell: | |
------------------------------- | |
docker exec -it <container_name> /bin/sh | |
docker exec -it postgres14 /bin/sh | |
Docker run history: | |
------------------- | |
history | grep | "docker run" | |
Remove container: | |
----------------- | |
docker rm <container_name> | |
docker rm postgres14 | |
Access postgres console in docker: | |
---------------------------------- | |
docker exec -it postgres14 psql -U root -d simple_bank | |
Remove an image by ID: | |
---------------------- | |
docker rmi imageID | |
Run a container from an image: | |
------------------------------ | |
docker run --name simplebank -p 8080:8080 simplebank:latest | |
Show the network settings: | |
-------------------------- | |
docker container inspect postgres14 | |
Show docker network: | |
--------------------- | |
docker network ls | |
Create docker network: | |
---------------------- | |
docker network create bank-network | |
docker network connect --help | |
Connect postgres container to bank-network: | |
------------------------------------------- | |
docker network connect bank-network postgres14 | |
Run all docker container by compose: | |
------------------------------------ | |
docker compose up | |
Remove all docker container: | |
---------------------------- | |
docker compose down |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment