Skip to content

Docker Commands

Posted on:May 20, 2020 at 12:00 AM

tp.web.random_picture

List of core Docker commands you must know.

Table of contents

Open Table of contents

Pull

# pulls `latest` Docker image of nginx
docker pull nginx

# pulls version 1.23 image of nginx
docker pull nginx:1.23

List Images

docker images

Create a container

docker create {image-name}

Run a container

docker start {container-id}
docker run {name}:{tag}

# Runs a container in the background
docker run -d nginx:1.23

Container Naming

docker run --name web-app -d -p 9000:80 nginx:1.23

Stop a container(s)

# stops the container by container id
docker stop {container-id}
# stops the contianer by container name
docker stop {container-name}
# stops multiple container having id and/or name
docker stop {container-id} {container-name}

List containers

# Lists all running containers
docker ps
# List all containers either running or stopped
docker ps -a

View logs from a running container

docker logs {container-id}

Port binding

# Use -p or --publish option for port binding.
# Here,
# HOST_PORT -> 9000
# CONTAINER_PORT -> 80
docker run -d -p 9000:80 nginx:1.23

Build an image

# -t or --tag
docker build -t node-app:1.0 .

References