Skip to content

Latest commit

 

History

History
123 lines (83 loc) · 1.91 KB

docker.md

File metadata and controls

123 lines (83 loc) · 1.91 KB

Docker Commands

1. Create an image:

# Inside the folder with Dockerfile
docker build -t <image_name> .

2. Run an image:

  • Regular:

    docker run <image_name>
  • Binding a port at run time:

    docker run -p <container_port>:<host_port> <image_name>
  • Setting a name for the container at run time:

    docker run --name <container name> <image name>
  • Running a container in the background (detached):

    docker run -d <image_name>

3. List your images:

docker image ls

4. Delete a specific image:

docker image rm [image name]

5. Delete all existing images:

docker image rm $(docker images -a -q)

6. List all existing containers (running and not running):

docker ps -a

7. Stop a specific container:

docker stop [container name]

8. Stop all running containers:

docker stop $(docker ps -a -q)

9. Delete a specific container (only if stopped):

docker rm [container name]

10. Delete all containers (only if stopped):

docker rm $(docker ps -a -q)

11. Display logs of a container:

docker logs [container name]

12. Build using docker compose:

# In the repository with docker-compose.yml
docker-compose build

13. Starting containers using docker compose:

  • Regular:

    # In the repository with docker-compose.yml
    docker-compose up
  • Background (Detached mode):

    # In the repository with docker-compose.yml
    docker-compose up -d

14. Deleting all untagged(dangling) images:

docker rmi $(docker images -f “dangling=true” -q)

15. Executing a command in a running container:

docker exec <command>