DEV Community

Cover image for Docker's Command
Ali Reza
Ali Reza

Posted on • Updated on

Docker's Command

Some important Docker commands

Build Image from a Dockerfile

docker build -t {IMAGE_NAME} .

List local images

docker images
docker image ls
docker image ls -a

Remove one or more images

docker rmi {IMAGE_NAME} {IMAGE_NAME}

remove unused images (all images)

docker images prune
docker images prune -a

Login to Docker Hub (or private repository)

docker login -u {USERNAME}

Pulling image from Docker Hub (or private repository)

docker pull {IMAGE_NAME}

Start container

docker run {IMAGE_NAME}
docker run --name {container_name} {IMAGE_NAME}
docker run -p {HOST_PORT}:{CONTAINER_PORT} --name {container_name} {IMAGE_NAME}

Stop container

docker stop {CONTAINER_NAME/CONTAINER_ID}

Remove stoped container

docker rm {CONTAINER_NAME/CONTAINER_ID}

run command in container

docker exec -it {CONTAINER_NAME/CONTAINER_ID} {COMMAND}

Fetch container logs

docker logs {CONTAINER_NAME/CONTAINER_ID}
docker logs {CONTAINER_NAME/CONTAINER_ID} -f

List of running containers

docker ps
docker ps -a

Container state

docker container states


Compose

Define and run multi-container applications with Docker.
read_more

Builds, (re)creates, starts, and attaches to containers for a service.

docker compose up
docker compose up -d

Fetch container service

docker compose logs {SERVICE_NAME}
docker compose logs {SERVICE_NAME} -f

run command in service

docker compose exec -it {SERVICE_NAME} {COMMAND}


Useful links

Docker
Docker Hub
Docker Compose
Awesome compose projects

Top comments (0)