The most popular Docker commands

  Oct 10, 2017      2m
   

List the popular Docker commands used daily. Standard docker run: docker run --name containerName -p hostPort:appPortInDocker -e KEY=VALUE -t repo:tag. Remove all docker containers or images.

The most popular Docker commands

The Docker commands that I use mostly. It worths listing all the essential commands.

Docker commands

Standard Docker run
$ docker run –name containerName -p hostPort:appPortInDocker -e KEY=VALUE -t repo:tag

Standard Docker build
$ docker build -t repo:tag .
(the dot at the last command means build the Dockerfile file in the current directory)

Stop the container
$ docker stop containerName

Start the container later
$ docker start containerName

View running containers
$ docker ps

View all images
$ docker images

View docker container in details
$ docker inspect ID-or-NAME (eg. $ docker inspect 62a932a5c143)

Remove all containers
$ docker rm $(docker ps -a -q)

Remove all images
$ docker rmi $(docker images -q)

Run docker without sudo $ sudo addgroup -a $(whoami) docker

Run docker in interactive mode
$ docker run -it –rm busybox:latest

  • busybox is the image name
  • latest is the version

Detaching containers without stopping them Press Ctrl-P and then Ctrl-Q to detach.

Docker-compose commands

Run docker compose
$ docker-compose up
$ docker-compose up -d (detached mode)
$ docker-compose --file my_docker_compose_file.yml up -d (if you want to run specific docker-compose file)

Restart a running container started by docker-compose
$ docker-compose restart

Stop a running container started by docker-compose
$ docker-compose stop